package com.originskyseed.platform.user.service.impl;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.annotation.Resource;

import com.originskyseed.platform.user.mapper.*;
import com.originskyseed.platform.user.model.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONArray;
import com.originskyseed.platform.common.api.util.QueryAppUtil;
import com.originskyseed.platform.common.api.util.TimeFormatUtil;
import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.tenant.util.TenantCodeUtil;
import com.originskyseed.platform.core.util.bean.PrimaryKeyGeneratorUtil;
import com.originskyseed.platform.user.service.IPlayerService;

/**
 * 玩家信息表Service接口实现类（OSI_PLAYER）
 *
 * @author wlj
 */
@DubboService
@Component("playerService")
public class PlayerServiceImpl implements IPlayerService {

	private static final Logger logger = LoggerFactory.getLogger(PlayerServiceImpl.class);
	@Resource
	private PlayerMapper playerMapper;

	@Resource
	private PlayerRelateLoginMapper playerRelateLoginMapper;

	@Resource
	private PlayerRelateRechargeMapper playerRelateRechargeMapper;

	@Resource
	private DeptMapper deptMapper;

	@Resource
	private UserInfoMapper userInfoMapper;

	@Resource
	private PlayerRelateConsumeMapper playerRelateConsumeMapper;

	@Resource
	private PlayerRelateViewLiveMapper playerRelateViewLiveMapper;

	@Resource
	private AnchorRelateByoFansMapper anchorRelateByoFansMapper;

	@Resource
	private HighQualityUserMapper highQualityUserMapper;

	/**
	 * 删除记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKey(String id) throws Exception {
		return this.playerMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 批量删除记录
	 *
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKeys(List<String> ids) throws Exception {
		return this.playerMapper.deleteByPrimaryKeys(ids);
	}

	/**
	 * 插入记录
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insert(Player record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.playerMapper.insert(record);
	}

	/**
	 * 插入记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertSelective(Player record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.playerMapper.insertSelective(record);
	}

	/**
	 * 更新记录
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKey(Player record) throws Exception {
		record.setUpdateTime(new Date());
		return this.playerMapper.updateByPrimaryKey(record);
	}

	/**
	 * 更新记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKeySelective(Player record) throws Exception {
		record.setUpdateTime(new Date());
		return this.playerMapper.updateByPrimaryKeySelective(record);
	}


	/**
	 * 更新记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	public int updateByPrimaryKeySelective(String tenantCode,Player record) throws Exception
	{
		if(tenantCode!=null&&StringUtils.isNotBlank(tenantCode))
		{
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return updateByPrimaryKeySelective(record);
	}

	/**
	 * 更新记录（仅非空值字段）
	 *
	 * @param tenantCode
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKeySelectiveByTenantCode(String tenantCode,List<PlayerRelateRecharge> playerRelateRechargeList) throws Exception
	{
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		if(playerRelateRechargeList!=null&&playerRelateRechargeList.size()>0)
		{
			for(int i=0;i<playerRelateRechargeList.size();i++)
			{
				PlayerRelateRecharge playerRelateRecharge=playerRelateRechargeList.get(i);

				String playerId=playerRelateRecharge.getPlayerId();
				if(playerId==null||StringUtils.isBlank(playerId))
				{
					playerRelateRecharge.setRechargeIsUpdate(3);
				}
				else {
					BigDecimal amount = playerRelateRecharge.getAmount();

					//同步玩家
					Player player = playerMapper.selectPlayerByPlayerId(playerId);
					playerRelateRecharge.setRechargeIsUpdate(1);
					if (player == null) {
						playerRelateRecharge.setRechargeIsUpdate(2);
					} else {
						//获取累充金额
						if (amount != null && player.getAmount() != null) {
							amount = amount.add(player.getAmount());
						}
						player.setAmount(amount);

						/*//获取最后登录时间
						Date lastLoginTime = playerRelateLoginMapper.selectLastLoginTimeByPlayerId(playerId);
						player.setLastLoginTime(lastLoginTime);
						player.setUpdateTime(new Date());
						this.playerMapper.updateByPrimaryKeySelective(player);*/
					}

					//同步自带粉
					AnchorRelateByoFans anchorRelateByoFans = anchorRelateByoFansMapper.selectAnchorRelateByoFansByPlayerId(playerId);
					if (anchorRelateByoFans != null) {
						//获取累充金额
						if (amount != null && anchorRelateByoFans.getAmount() != null) {
							amount = amount.add(player.getAmount());
						}
						anchorRelateByoFans.setAmount(amount);

						anchorRelateByoFansMapper.updateByPrimaryKeySelective(anchorRelateByoFans);
					}
				}

				playerRelateRecharge.setUpdateTime(new Date());
				playerRelateRechargeMapper.updateByPrimaryKeySelective(playerRelateRecharge);
			}
		}
		return 1;
	}

	/**
	 * 玩家是否在线
	 * @param list
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updatePlayerIsOnLineByList(List<String> list) throws Exception {
		return this.playerMapper.updatePlayerIsOnLineByList(list);
	}

	/**
	 * 玩家是否在线
	 * @param playerList
	 * @param tenantCode
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updatePlayerIsOnLineByListTenantCode(String tenantCode,List<Player> playerList) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		//玩家ID
		List<String> playerIdsList = new ArrayList<>();
		if (playerList != null && playerList.size() > 0) {
			for (Player playerInfo : playerList) {
				String playerId=playerInfo.getPlayerId();
				if (playerId != null && StringUtils.isNotBlank(playerId)) {
					playerIdsList.add(playerId);

					//获取最后登录时间
					/*Date lastLoginTime = playerRelateLoginMapper.selectLastLoginTimeByPlayerId(playerId);
					playerInfo.setLastLoginTime(lastLoginTime);
					playerInfo.setUpdateTime(new Date());
					this.playerMapper.updateByPrimaryKeySelective(playerInfo);*/
				}
			}
		}
		TreeMap<String, Object> paramMap = new TreeMap<>();
		paramMap.put("playerIds", String.join(",",playerIdsList));
		Map resultMap = QueryAppUtil.query("playerOnlineUrl", 1, paramMap);
		Integer code = Integer.parseInt(resultMap.get("code").toString());
		JSONArray data = new JSONArray();
		if (code == 1) {
			data = JSONArray.parseArray(resultMap.get("data").toString());
		} else {
			logger.error(resultMap.get("msg").toString());
		}
		List<String> updateList = new ArrayList<>();
		if (data != null && data.size() > 0) {
			for (Object playerIds : data) {
				updateList.add((String) playerIds);
			}
		}
		if(updateList!=null&&updateList.size()>0) {
			return this.updatePlayerIsOnLineByList(updateList);
		}
		return 1;
	}

	/**
	 * 查询记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public Player selectByPrimaryKey(String id) throws Exception {
		return this.playerMapper.selectByPrimaryKey(id);
	}

	/**
	 * 查询记录,根据玩家id
	 *
	 * @param playerId
	 * @return
	 * @throws Exception
	 */
	public Player selectByPlayerId(String playerId) throws Exception {
		return this.playerMapper.selectByPlayerId(playerId);
	}


	/**
	 * 查询记录,根据玩家id
	 *
	 * @param playerId
	 * @return
	 * @throws Exception
	 */
	public Player selectByPlayerId(String tenantCode,String playerId) throws Exception
	{
		if(tenantCode!=null&&StringUtils.isNotBlank(tenantCode))
		{
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.playerMapper.selectByPlayerId(playerId);
	}

	/**
	 * 查询列表
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Player> selectList(Player record) throws Exception {
		return this.playerMapper.selectList(record);
	}

	/**
	 * 查询列表
	 * @param record
	 * @param tenantCode
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Player> selectListTenantCode(Player record, String tenantCode) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.selectList(record);
	}

	/**
	 * 查询金额,根据子渠道id
	 *
	 * @param
	 * @return
	 * @throws Exception
	 */
	public BigDecimal selectAmountByChannelSubId(String tenantCode,String channelSubId) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.playerMapper.selectAmountByChannelSubId(channelSubId);
	}

	/**
	 * 分页查询列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Player> selectPlayerListByPageByTenantCode(String tenantCode,Map<String, Object> params, BasePage<Player> page) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		params.put("page", page);
		List<Player> list = this.playerMapper.selectListByPage(params);
		page.setResults(list);
		return page;
	}


	/**
	 * 分页查询列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Player> selectListByPage(Map<String, Object> params, BasePage<Player> page) throws Exception {
		params.put("page", page);
		List<Player> list = this.playerMapper.selectListByPage(params);
		if (list != null && list.size() > 0) {
			for (Player player : list) {
				if (player != null && player.getChannelSubId() != null) {
					UserInfo userInfo = this.userInfoMapper.selectByOtherAccount(player.getChannelSubId());
					if (userInfo != null) {
						if (userInfo.getId() != null) {
							player.setBelongBusinessId(userInfo.getId());
						}
						if (userInfo.getName() != null) {
							player.setBelongBusinessName(userInfo.getName());
						}
						if (userInfo.getAccount() != null) {
							player.setBelongBusinessAccount(userInfo.getAccount());
						}

					}
				}
			}
		}
		page.setResults(list);
		return page;
	}

	/**
	 * 查询玩家
	 *
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<TaskSelectPlayerVO> taskSelectPlayerToSalerListByPage(Map<String, Object> params, BasePage<TaskSelectPlayerVO> page, UserInfo userInfo) throws Exception {
		params.put("page", page);
		List<TaskSelectPlayerVO> list = this.playerMapper.taskSelectPlayerToSalerListByPage(params);
		if (list != null && list.size() > 0) {
			for (TaskSelectPlayerVO player : list) {
				// 玩家昵称变成名称，为了任务新增的时候插入维护表
				player.setName(player.getNickName());
				player.setUserId(player.getPlayerId());
			}
		}
		page.setResults(list);
		return page;
	}

	/**
	 * 查询玩家
	 *
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<TaskSelectPlayerVO> taskSelectPlayerToAnchorListByPage(Map<String, Object> params, BasePage<TaskSelectPlayerVO> page) throws Exception {
		params.put("page", page);
		List<TaskSelectPlayerVO> list = this.playerMapper.taskSelectPlayerToAnchorListByPage(params);
		if (list != null && list.size() > 0) {
			for (TaskSelectPlayerVO player : list) {
				// 玩家昵称变成名称，为了任务新增的时候插入维护表
				player.setName(player.getNickName());
				player.setUserId(player.getPlayerId());
			}
		}
		page.setResults(list);
		return page;
	}

	/**
	 * 玩家注册信息_分页查询列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Player> selectLoginListByPage(Map<String, Object> params, BasePage<Player> page) throws Exception {
		params.put("page", page);
		List<Player> list = this.playerMapper.selectLoginListByPage(params);
		// 统计登录次数
		if (list != null && list.size() > 0) {
			for (Player player : list) {
				if (player != null && player.getAccount() != null) {
					int count = this.playerRelateLoginMapper.loginCountByAccout(player.getAccount());
					player.setLoginCount(count);
				}
			}
		}
		page.setResults(list);
		return page;
	}

	/**
	 * 导出玩家注册信息
	 *
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Player> selectLoginListToExcel(Map<String, Object> params) throws Exception {
		BasePage<Player> page = new BasePage();
		page.setPageNo(1);
		page.setPageSize(999999);
		params.put("page", page);
		List<Player> list = this.playerMapper.selectLoginListByPage(params);
		// 统计登录次数
		if (list != null && list.size() > 0) {
			for (Player player : list) {
				if (player != null && player.getAccount() != null) {
					int count = this.playerRelateLoginMapper.loginCountByAccout(player.getAccount());
					player.setLoginCount(count);
				}
			}
		}
		return list;
	}

	/**
	 * 推广平台_业务员_玩家信息分页查询
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Player> selectPlayerListByPage(Map<String, Object> params, BasePage<Player> page, UserInfo userInfo) throws Exception {
		params.put("page", page);
		Dept dept = this.deptMapper.selectByPrimaryKey(userInfo.getDeptId());
		List<String> userIdList = new ArrayList<>();
		List<String> deptIdList = new ArrayList<>();
		if (dept != null && userInfo.getType() != 6) {
			if (dept.getType() == 5) { // 小组
				deptIdList.add(dept.getId());
			} else {
				this.selectDeptSon(dept.getCode(), deptIdList);
				deptIdList.add(dept.getId());
			}

			userIdList = this.userInfoMapper.selectSalesmanIdsByDeptIds(deptIdList);// 玩家第三方主键
		} else {
			userIdList.add(userInfo.getOtherAccount());
		}
		params.put("userIdList", userIdList);
		List<Player> list = this.playerMapper.selectPlayerListByPage(params);
		/*if (list != null && list.size() > 0) {
			for (Player player : list) {
				if (player != null && player.getChannelSubId() != null) { // 子渠道id
					player.setBelongBusinessId(player.getChannelSubId());
				}
				player.setUserId(player.getPlayerId());
				if (player.getNickName() != null) {
					player.setName(player.getNickName());
				}
			}
		}*/
		forTimeWay(list);
		page.setResults(list);
		return page;
	}

	/**
	 * 内容平台_主播_玩家信息分页查询
	 *
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Player> selectPlayerListToAnchorByPage(Map<String, Object> params, BasePage<Player> page, UserInfo userInfo) throws Exception {
		params.put("page", page);
		Dept dept = this.deptMapper.selectByPrimaryKey(userInfo.getDeptId());
		List<String> userIdList = new ArrayList<>();
		List<String> deptIdList = new ArrayList<>();
		if (dept != null && userInfo.getType() != 11) {
			if (dept.getType() == 3) { // 小组
				deptIdList.add(dept.getId());
			} else {
				this.selectDeptSon(dept.getCode(), deptIdList);
			}
			userIdList = this.userInfoMapper.selectAnchorOtherAccountsByDeptIds(deptIdList);
		} else {
			userIdList.add(userInfo.getOtherAccount());
		}
		params.put("userIdList", userIdList);
		List<Player> list = this.playerMapper.selectPlayerListToAnchorByPage(params);
		forTimeWay(list);
		page.setResults(list);
		return page;
	}

	/**
	 * 内容平台_OW_玩家信息分页查询
	 *
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Player> selectPlayerListToOWByPage(Map<String, Object> params, BasePage<Player> page, UserInfo userInfo) throws Exception {
		params.put("page", page);
		/*
		 * Dept dept = this.deptMapper.selectByPrimaryKey(userInfo.getDeptId()); List<String> userIdList = new ArrayList<>(); if (dept != null) { List<String> deptIdList = new ArrayList<>(); this.selectDeptSon(dept.getCode(), deptIdList); if (userInfo.getSourceSys() == 1) { //内容平台 userIdList = this.userInfoMapper.selectAnchorOtherAccountsByDeptIds(deptIdList); } } params.put("userIdList", userIdList);
		 */
		List<Player> list = this.playerMapper.selectPlayerListToOWByPage(params);
		if (list != null && list.size() > 0) {
			for (Player player : list) {
				player.setUserId(player.getPlayerId());
				String channelSubId = player.getChannelSubId();
				if (channelSubId != null && StringUtils.isBlank(channelSubId)) {
					UserInfo tempUser = userInfoMapper.selectByOtherAccount(channelSubId);
					player.setBelongBusinessName(tempUser == null ? "" : tempUser.getName());
				}
				/*
				 * if(player.getNickName() != null){ player.setName(player.getNickName()); }
				 */
			}
		}
		forTimeWay(list);
		page.setResults(list);
		return page;
	}

	/**
	 * 查询访问玩家的数量
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer pkSelectAnchorVisitsNumber(Map<String, Object> map, String tenantCode) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.pkSelectAnchorVisitsNumber(map);
	}

	/**
	 * 查询访问玩家的数量
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer pkSelectAnchorVisitsNumber(Map<String, Object> map) throws Exception {
		return this.playerMapper.pkSelectAnchorVisitsNumber(map);
	}

	/**
	 * 查询主播装换率
	 *
	 * @param anchorId
	 * @param tenantCode
	 * @return
	 * @throws Exception
	 */
	@Override
	public BigDecimal selectLiveRateByAnchorId(String anchorId, String tenantCode) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.selectLiveRateByAnchorId(anchorId);
	}

	/**
	 * 查询主播转换率
	 * @param anchorId
	 * @return
	 * @throws Exception
	 */
	@Override
	public BigDecimal selectLiveRateByAnchorId(String anchorId) throws Exception {
		return  this.playerMapper.selectLiveRateByAnchorId(anchorId);
	}

	/**
	 * 查询优质用户数
	 *
	 * @param map
	 * @param tenantCode
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer pkSelectHighQualityUserCount(Map<String, Object> map, String tenantCode) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.selectHighQualityUserCount(map);
	}

	/**
	 * 查询优质用户数量总数
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer selectHighQualityUserCount(Map<String, Object> map) throws Exception {
		return this.playerMapper.selectHighQualityUserCount(map);
	}

	/**
	 * 查询主播心动用户
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer selectHeartbeatCount(Map<String, Object> map, String tenantCode) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.playerMapper.selectHeartbeatCount(map);
	}

	/**
	 * 查询pk主播心动用户
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer pkSelectHeartbeatCount(Map<String, Object> map, String tenantCode) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.pkSelectHeartbeatCount(map);
	}

	/**
	 * 查询pk主播心动用户
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer pkSelectHeartbeatCount(Map<String, Object> map) throws Exception {
		return this.playerMapper.pkSelectHeartbeatCount(map);
	}

	/**
	 * pk查询新充总额
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@Override
	public BigDecimal pkSelectNewChargeAmountSum(Map<String, Object> map) throws Exception {
		return this.playerMapper.pkSelectNewChargeAmountSum(map);
	}

	/**
	 * pk查询新充总额
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@Override
	public BigDecimal pkSelectNewChargeAmountSum(Map<String, Object> map, String tenantCode) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.pkSelectNewChargeAmountSum(map);
	}

	/**
	 * 查询潜力用户数
	 *
	 * @param map
	 * @param tenantCode
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer pkSelectPotentialUsersCount(Map<String, Object> map, String tenantCode) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.pkSelectPotentialUsersCount(map);
	}

	/**
	 * 查询潜力用户数
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer pkSelectPotentialUsersCount(Map<String, Object> map) throws Exception {
		return this.playerMapper.pkSelectPotentialUsersCount(map);
	}

	/**
	 * 推广查询新充总额（定时任务）
	 *
	 * @param map
	 * @param tenantCode
	 * @return
	 * @throws Exception
	 */
	@Override
	public BigDecimal selectNewChargeAmountSumTenantCode(Map<String, Object> map, String tenantCode) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.playerMapper.pkSelectNewChargeAmountSum(map);
	}

	/**
	 * 推广平台_业务员_私域_用户流量池列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Player> selectPlayerPlowPoolListByPage(Map<String, Object> params, BasePage<Player> page) throws Exception {
		params.put("page", page);
		List<Player> list = this.playerMapper.selectPlayerPlowPoolListByPage(params);
		forTimeWay(list);
		page.setResults(list);
		return page;
	}

	/**
	 * 业务员_公域域用户流量池列表
	 *
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Player> selectPlayerPublicPlowPoolListByPage(Map<String, Object> params, BasePage<Player> page, UserInfo userInfo) throws Exception {
		params.put("page", page);
		Dept dept = this.deptMapper.selectByPrimaryKey(userInfo.getDeptId());
		List<String> userIdList = new ArrayList<>();
		if (dept != null) {
			List<String> deptIdList = new ArrayList<>();
			// 查询到体系层级
			this.selectDeptSon(dept.getCode(), deptIdList);
			if (deptIdList != null && deptIdList.size() > 0) {
				userIdList = this.userInfoMapper.selectSalesmanIdsByDeptIds(deptIdList);
			}
		}
		params.put("userIdList", userIdList);
		List<Player> list = new ArrayList<>();
		if (userIdList != null && userIdList.size() > 0) {
			list = this.playerMapper.selectPlayerPublicPlowPoolListByPage(params);
		}
		forTimeWay(list);
		page.setResults(list);
		return page;
	}

	/**
	 * 主播_公域用户流量池列表
	 *
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Player> selectPlayerPlowPoolListToAnchorByPage(Map<String, Object> params, BasePage<Player> page, UserInfo userInfo) throws Exception {
		params.put("page", page);
		Dept dept = this.deptMapper.selectByPrimaryKey(userInfo.getDeptId());
		// 查询工会部门id
		String selectLabourUnionId = this.selectLabourUnionId(dept.getCode());
		List<String> userIdList = new ArrayList<>();
		List<String> deptIdList = new ArrayList<>();
		if (dept != null) {
			if (dept != null && userInfo.getType() != 11) {
				if (dept.getType() == 3) { // 小组
					deptIdList.add(dept.getId());
				} else {
					this.selectDeptSon(dept.getCode(), deptIdList);
				}
			} else {
				userIdList.add(userInfo.getOtherAccount());
			}
			if (deptIdList != null && deptIdList.size() > 0) {
				userIdList = this.userInfoMapper.selectAnchorOtherAccountsByDeptIds(deptIdList);
			}
		}
		params.put("userIdList", userIdList);
		List<Player> list = new ArrayList<>();
		if (userIdList != null && userIdList.size() > 0) {
			list = this.playerMapper.selectPlayerPlowPoolListToAnchorByPage(params);
		}
		forTimeWay(list);
		page.setResults(list);
		return page;
	}

	/**
	 * 根据业务员Id查询公会Id
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public Player selectTradeBybelongBusinessId(String id) throws Exception {
		return this.playerMapper.selectTradeBybelongBusinessId(id);
	}

	/**
	 * 查询玩家id是否存在
	 *
	 * @param playerIds
	 * @return
	 * @throws Exception
	 */
	public List<String> selectPlayerIds(List<String> playerIds) throws Exception {
		return this.playerMapper.selectPlayerIds(playerIds);
	}

	/**
	 * 查询玩家id是否存在
	 *
	 * @param playerIds
	 * @return
	 * @throws Exception
	 */
	public List<String> selectPlayerIds(String tenantCode,List<String> playerIds) throws Exception
	{
		if(tenantCode!=null&&StringUtils.isNotBlank(tenantCode))
		{
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return selectPlayerIds(playerIds);
	}

	/**
	 * 根据player查询玩家信息
	 *
	 * @param player
	 * @return
	 * @throws Exception
	 */
	@Override
	public Player selectPlayerByPlayer(Player player) throws Exception {
		return this.playerMapper.selectPlayerByPlayer(player);
	}

	/**
	 * 批量插入记录
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public int insertBatch(List<Player> list) throws Exception {
		return this.playerMapper.insertBatch(list);
	}

	/**
	 * 批量插入记录
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public int insertBatch(String tenantCode,List<Player> list) throws Exception
	{
		if(tenantCode!=null&&StringUtils.isNotBlank(tenantCode))
		{
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return insertBatch(list);
	}

	/**
	 * 分页查询用户明细信息列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Player> selectUserDetailsByPage(Map<String, Object> params, BasePage<Player> page) throws Exception {
		params.put("page", page);
		// List<Player> list = this.playerMapper.selectUserDetailsByPage(params);
		List<Player> list = this.playerMapper.selectUserByPage(params);
		// 判断是否达标（累计充值达到10元或是注册之日观看直播达到3分钟）
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				Player player = list.get(i);
				String subChannelSubId=player.getChannelSubId();
				if(subChannelSubId!=null&&StringUtils.isNotBlank(subChannelSubId)) {
					UserInfo userInfo=userInfoMapper.selectByOtherAccount(subChannelSubId);
					player.setBelongBusinessName(userInfo==null?"":userInfo.getName());
				}
                HighQualityUser highQualityUser=highQualityUserMapper.selectByPlayerId(player.getPlayerId());
				if(highQualityUser!=null)
				{
					if(highQualityUser.getAmount()!=null&&highQualityUser.getAmount().compareTo(new BigDecimal(10))>0)
					{
						player.setStandardDate(highQualityUser.getCompletionTime());
						player.setIsStandard(1);
					}
					else
					{
						if(highQualityUser.getViewTimes()!=null) {
							Integer seconds = highQualityUser.getViewTimes().intValue();
							if (seconds != null && seconds / 60 >= 3) // 大于3分钟
							{
								player.setStandardDate(highQualityUser.getViewCompletionTime());
								player.setIsStandard(1);
							}
						}
					}
				}
			}
		}
		page.setResults(list);
		return page;
	}

	/**
	 * 分页查询优质用户列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Player> selectHighQualityUserByPage(Map<String, Object> params, BasePage<Player> page) throws Exception {
		params.put("page", page);
		List<Player> list = this.playerMapper.selectHighQualityUserByPage(params);
		page.setResults(list);
		return page;
	}

	/**
	 * 分页查询活跃登录用户列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Player> selectActiveLoginUserByPage(Map<String, Object> params, BasePage<Player> page) throws Exception {
		params.put("page", page);
		List<Player> list = this.playerMapper.selectActiveLoginUserByPage(params);
		page.setResults(list);
		return page;
	}

	/**
	 * 查询设备数量
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Integer selectEquipmentNum(List<String> list) throws Exception {
		return this.playerMapper.selectEquipmentNum(list);
	}

	/**
	 * 查询新用户充值金额
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public BigDecimal selectNewUserRechargeAmount(List<String> list) throws Exception {
		return this.playerMapper.selectNewUserRechargeAmount(list);
	}

	/**
	 * 查询新用户充值金额
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public BigDecimal selectContentNewUserRechargeAmount(List<String> list) throws Exception {
		return this.playerMapper.selectContentNewUserRechargeAmount(list);
	}

	/**
	 * 查询优质用户数量
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Integer selectHighQualityUserNum(List<String> list) throws Exception {
		return this.playerMapper.selectHighQualityUserNum(list);
	}

	/**
	 * 查询内容优质用户数量
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Integer selectContentHighQualityUserNum(List<String> list) throws Exception {
		return this.playerMapper.selectContentHighQualityUserNum(list);
	}

	/**
	 * 查询充值用户数量
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Integer selectRechargeUserNum(List<String> list) throws Exception {
		return this.playerMapper.selectRechargeUserNum(list);
	}

	/**
	 * 查询内容消费充值用户数量
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Integer selectContentRechargeUserNum(List<String> list) throws Exception {
		return this.playerMapper.selectContentRechargeUserNum(list);
	}

	/**
	 * 查询充值用户数量
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public BigDecimal selectRechargeUserAmount(List<String> list) throws Exception {
		return this.playerMapper.selectRechargeUserAmount(list);
	}

	/**
	 * 查询内容累计充值额度
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public BigDecimal selectContentRechargeUserAmount(List<String> list) throws Exception {
		return this.playerMapper.selectContentRechargeUserAmount(list);
	}

	/**
	 * 查询成本和毛利和净利润
	 *
	 * @param userIdList       用户集合
	 * @param list       业务员id集合
	 * @param type       0 日 1 周 2 月 3 季 4 年
	 * @param selectType 0查询推广类，1查询内容类
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectBasePayAndGrossProfit(List<String> userIdList,List<String> list, int type, int selectType) throws Exception {
		Map<String, Object> resultMap = new HashMap<>();
		// 查询成本
		BigDecimal basePay = BigDecimal.ZERO;
		if (userIdList != null && userIdList.size()>0) {
			//if (selectType == 0) {
				basePay = this.playerMapper.selectBasePay(userIdList);
			//} else {
			//	basePay = this.playerMapper.selectAnchorBasePay(userIdList);
			//}
		}

		// 根据日期平摊成本,和查询毛利
		String startTime = null;
		String endTime = null;
		DateUtils dateUtils = new DateUtils();
		// 日
		if (type == 0) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String date = sdf.format(new Date());
			startTime = date;
			endTime = date;

			// 当前月的天数
			int monthDay = dateUtils.getCurrentMonthDay();
			// basePay = basePay.divide(new BigDecimal(monthDay),3,BigDecimal.ROUND_DOWN);
			// 周
		} else if (type == 1) {
			startTime = dateUtils.getCurrentWeekDayStartTime();
			endTime = dateUtils.getCurrentWeekDayEndTime();

			// basePay = basePay.divide(new BigDecimal(4),3,BigDecimal.ROUND_DOWN);
			// 月
		} else if (type == 2) {
			startTime = dateUtils.getCurrentMonthStartTime();
			endTime = dateUtils.getCurrentMonthEndTime();
			// 季
		} else if (type == 3) {
			startTime = dateUtils.getCurrentQuarterStartTime();
			endTime = dateUtils.getCurrentQuarterEndTime();

			// basePay = basePay.multiply(new BigDecimal(4));
			// 年
		} else if (type == 4) {
			startTime = dateUtils.getCurrentYearStartTime();
			endTime = dateUtils.getCurrentYearEndTime();

			// basePay = basePay.multiply(new BigDecimal(12));
		}

		// 封装参数
		Map<String, Object> map = new HashMap<>();
		map.put("list", list);
		map.put("startTime", startTime);
		map.put("endTime", endTime);

		// 毛利
		BigDecimal grossProfit;
		if (selectType == 0) {
			grossProfit = this.playerMapper.selectGrossProfit(map).multiply(new BigDecimal(0.3));
		} else {
			grossProfit = this.playerMapper.selectAnchorGrossProfit(map).multiply(new BigDecimal(0.3));
		}
		resultMap.put("basePay", basePay);
		resultMap.put("grossProfit", grossProfit);
		// resultMap.put("profit", grossProfit.subtract(basePay));
		return resultMap;
	}

	/**
	 * 查询LTV
	 *
	 * @param list       用户集合
	 * @param selectType 0查询推广类，1查询内容类
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectUserLtv(List<String> list, int selectType) throws Exception {
		Map<String, Object> resultMap = new HashMap<>();

		BigDecimal firstDayLtv = BigDecimal.ZERO;
		BigDecimal twoDayLtv = BigDecimal.ZERO;
		BigDecimal threeDayLtv = BigDecimal.ZERO;
		BigDecimal sevenDayLtv = BigDecimal.ZERO;
		BigDecimal fifteenDayLtv = BigDecimal.ZERO;
		BigDecimal thirtyDayLtv = BigDecimal.ZERO;
		BigDecimal sixtyDayLtv = BigDecimal.ZERO;

		// 封装参数
		Map<String, Object> query = new HashMap<>();
		query.put("list", list);
		// 查询推广类
		if (selectType == 0) {
			query.put("day", 0);
			firstDayLtv = getLtv(this.playerMapper.selectSalesmanUserLtvByMonth(query));
			query.put("day", 1);
			twoDayLtv = getLtv(this.playerMapper.selectSalesmanUserLtvByMonth(query));
			query.put("day", 3);
			threeDayLtv = getLtv(this.playerMapper.selectSalesmanUserLtvByMonth(query));
			query.put("day", 7);
			sevenDayLtv = getLtv(this.playerMapper.selectSalesmanUserLtvByMonth(query));
			query.put("day", 15);
			fifteenDayLtv = getLtv(this.playerMapper.selectSalesmanUserLtvByMonth(query));
			query.put("day", 30);
			thirtyDayLtv = getLtv(this.playerMapper.selectSalesmanUserLtvByMonth(query));
			query.put("day", 60);
			sixtyDayLtv = getLtv(this.playerMapper.selectSalesmanUserLtv(query));
		} else {
			query.put("day", 0);
			firstDayLtv = getLtv(this.playerMapper.selectAnchorUserLtvByMonth(query));
			query.put("day", 1);
			twoDayLtv = getLtv(this.playerMapper.selectAnchorUserLtvByMonth(query));
			query.put("day", 3);
			threeDayLtv = getLtv(this.playerMapper.selectAnchorUserLtvByMonth(query));
			query.put("day", 7);
			sevenDayLtv = getLtv(this.playerMapper.selectAnchorUserLtvByMonth(query));
			query.put("day", 15);
			fifteenDayLtv = getLtv(this.playerMapper.selectAnchorUserLtvByMonth(query));
			query.put("day", 30);
			thirtyDayLtv = getLtv(this.playerMapper.selectAnchorUserLtvByMonth(query));
			query.put("day", 60);
			sixtyDayLtv = getLtv(this.playerMapper.selectAnchorUserLtv(query));
		}

		resultMap.put("firstDayLtv", firstDayLtv);
		resultMap.put("twoDayLtv", twoDayLtv);
		resultMap.put("threeDayLtv", threeDayLtv);
		resultMap.put("sevenDayLtv", sevenDayLtv);
		resultMap.put("fifteenDayLtv", fifteenDayLtv);
		resultMap.put("thirtyDayLtv", thirtyDayLtv);
		resultMap.put("sixtyDayLtv", sixtyDayLtv);
		return resultMap;
	}

	/**
	 * 查询利润明细
	 *
	 * @param date       日期
	 * @param list       用户集合
	 * @param selectType 0查询推广类，1查询内容类
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectProfitDetails(String date,List<String> userIdList, List<String> list, int selectType) throws Exception {
		Map<String, Object> resultMap = new HashMap<>();
		// 查询成本
		BigDecimal basePay = BigDecimal.ZERO;
		if(userIdList.size()>0){
			//if (selectType == 0) {
				basePay = this.playerMapper.selectBasePay(userIdList);
			//} else {
			//	basePay = this.playerMapper.selectAnchorBasePay(list);
			//}
		}


		// 根据日期
		String startTime = date + " 00:00:00";
		String endTime = date + " 23:59:59";

		// 封装参数
		Map<String, Object> map = new HashMap<>();
		map.put("list", list);
		map.put("startTime", startTime);
		map.put("endTime", endTime);
		// 毛利
		BigDecimal grossProfit;
		if (selectType == 0) {
			grossProfit = this.playerMapper.selectGrossProfit(map).multiply(new BigDecimal(0.3)).setScale(2, BigDecimal.ROUND_HALF_UP);
		} else {
			grossProfit = this.playerMapper.selectAnchorGrossProfit(map).multiply(new BigDecimal(0.3)).setScale(2, BigDecimal.ROUND_HALF_UP);
		}

		resultMap.put("basePay", basePay);
		resultMap.put("grossProfit", grossProfit);
		// resultMap.put("profit", grossProfit.subtract(basePay));
		return resultMap;
	}

	/**
	 * 查询营收值
	 *
	 * @param type
	 * @param list
	 * @param selectType 0查询推广类，1查询内容类
	 * @return
	 * @throws Exception
	 */
	public BigDecimal selectRevenueValue(Integer type, List<String> list, Integer selectType) throws Exception {
		// 根据日期平摊成本,和查询毛利
		String startTime = null;
		String endTime = null;
		DateUtils dateUtils = new DateUtils();
		// 昨日
		if(type==-1){
			startTime = dateUtils.getYesterday();
			endTime =  dateUtils.getYesterday();

			// 日
		}else if (type == 0) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String date = sdf.format(new Date());
			startTime = date;
			endTime = date;

			// 周
		} else if (type == 1) {
			startTime = dateUtils.getCurrentWeekDayStartTime();
			endTime = dateUtils.getCurrentWeekDayEndTime();

			// 月
		} else if (type == 2) {
			startTime = dateUtils.getCurrentMonthStartTime();
			endTime = dateUtils.getCurrentMonthEndTime();
			// 季
		} else if (type == 3) {
			startTime = dateUtils.getCurrentQuarterStartTime();
			endTime = dateUtils.getCurrentQuarterEndTime();

			// 年
		} else if (type == 4) {
			startTime = dateUtils.getCurrentYearStartTime();
			endTime = dateUtils.getCurrentYearEndTime();

		}

		// 封装参数
		Map<String, Object> map = new HashMap<>();
		map.put("list", list);
		map.put("startTime", startTime);
		map.put("endTime", endTime);

		// 营收值
		BigDecimal revenueValue;
		if (selectType == 0) {
			revenueValue = this.playerMapper.selectGrossProfit(map);
		} else {
			revenueValue = this.playerMapper.selectAnchorGrossProfit(map);
		}
		return revenueValue;
	}

	/**
	 * 查询优质用户
	 *
	 * @param list
	 * @param selectType 0查询推广类，1查询内容类
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectHighQualityUsers(List<String> list, Integer selectType) throws Exception {
		// 查询
		Map<String, Object> query = new HashMap<>();
		query.put("list", list);
		// 查询优质用户和潜在用户
		Integer highQualityNum;
		Integer potentialNum;
		if (selectType == 0) {
			highQualityNum = this.playerMapper.selectHighQualityUsers(query);
			potentialNum = this.playerMapper.selectPotentialUsers(query);
		} else {
			highQualityNum = this.playerMapper.selectContentHighQualityUsers(query);
			potentialNum = this.playerMapper.selectContentPotentialUsers(query);
		}

		// 查询上周的优质用户
		DateUtils dateUtils = new DateUtils();
		String date = dateUtils.getBeforeDate(7);
		query.put("date", date);
		Integer lastWeekHighQualityNum;
		if (selectType == 0) {
			lastWeekHighQualityNum = this.playerMapper.selectHighQualityUsers(query);
		} else {
			lastWeekHighQualityNum = this.playerMapper.selectContentHighQualityUsers(query);
		}

		// 封装返回对象
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("highQualityNum", highQualityNum);
		resultMap.put("potentialNum", potentialNum);
		resultMap.put("lastWeekHighQualityNum", lastWeekHighQualityNum);
		resultMap.put("highestPeak", highQualityNum);

		return resultMap;
	}


	/**
	 * 查询优质用户
	 *
	 * @param list
	 * @param selectType 0查询推广类，1查询内容类
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectHighQualityUsers(int type,List<String> list, Integer selectType) throws Exception {
		// 查询
		Map<String, Object> query = new HashMap<>();
		query.put("list", list);
		String startTime = "";
		String endTime =  "";
		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String date = sdf.format(new Date());
			startTime = date;
			endTime = date;

			// 周
		} else if (type == 1) {
			startTime = dateUtils.getCurrentWeekDayStartTime();
			endTime = dateUtils.getCurrentWeekDayEndTime();

			// 月
		} else if (type == 2) {
			startTime = dateUtils.getCurrentMonthStartTime();
			endTime = dateUtils.getCurrentMonthEndTime();
			// 季
		}

		query.put("startTime",startTime);
		query.put("endTime",endTime);
		// 查询优质用户和潜在用户
		Integer highQualityNum;
		Integer potentialNum;
		if (selectType == 0) {
			highQualityNum = this.playerMapper.selectHighQualityUsers(query);
			potentialNum = this.playerMapper.selectPotentialUsers(query);
		} else {
			highQualityNum = this.playerMapper.selectContentHighQualityUsers(query);
			potentialNum = this.playerMapper.selectContentPotentialUsers(query);
		}

		// 封装返回对象
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("highQualityNum", highQualityNum);
		resultMap.put("potentialNum", potentialNum);
		return resultMap;
	}

	/**
	 * 查询新充金额 , 或者累充金额
	 *
	 * @param type       0 日 1 周 2 月
	 * @param list
	 * @param queryType  0 新充金额 1 累充金额
	 * @param selectType 0查询推广类，1查询内容类
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectNewChargeAmount(int type, List<String> list, int queryType, int selectType) throws Exception {
		// 返回的对象
		Map<String, Object> resultMap = new HashMap<>();
		Map<String, Object> query = new HashMap<>();
		query.put("list", list);
		query.put("queryType", queryType);

		// 时间工具类
		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			query.put("date", "%Y-%m-%d %H");
			String[] hoursList = dateUtils.hoursList;

			// 获取今日数据
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String date = sdf.format(new Date());
			query.put("startTime", date);
			query.put("endTime", date);
			List<Map<String, Object>> mapList;
			if (selectType == 0) {
				mapList = this.playerMapper.selectNewChargeAmount(query);
			} else {
				mapList = this.playerMapper.selectContentNewChargeAmount(query);
			}

			List<BigDecimal> dataList = new ArrayList<>();
			for (String hours : hoursList) {
				boolean flag = true;
				for (Map<String, Object> map : mapList) {
					if (hours.equals(map.get("queryDate"))) {
						dataList.add((BigDecimal) map.get("amount"));
						flag = false;
					}
				}
				if (flag) {
					dataList.add(BigDecimal.ZERO);
				}
			}
			// 获取今日总额
			// 获取最大值
			BigDecimal amount;
			BigDecimal maxAmount;
			if (selectType == 0) {
				amount = this.playerMapper.selectNewChargeAmountSum(query);
				maxAmount = this.playerMapper.selectNewChargeAmountMax(query);
			} else {
				amount = this.playerMapper.selectContentNewChargeAmountSum(query);
				maxAmount = this.playerMapper.selectContentNewChargeAmountMax(query);
			}

			// 获取昨天数据
			List<BigDecimal> lastDataList = new ArrayList<>();
			String yesterday = dateUtils.getYesterday();
			query.put("startTime", yesterday);
			query.put("endTime", yesterday);
			if (selectType == 0) {
				mapList = this.playerMapper.selectNewChargeAmount(query);
			} else {
				mapList = this.playerMapper.selectContentNewChargeAmount(query);
			}
			for (String hours : hoursList) {
				boolean flag = true;
				for (Map<String, Object> map : mapList) {
					if (hours.equals(map.get("queryDate"))) {
						lastDataList.add((BigDecimal) map.get("amount"));
						flag = false;
					}
				}
				if (flag) {
					lastDataList.add(BigDecimal.ZERO);
				}
			}
			BigDecimal lastAmount;
			if (selectType == 0) {
				lastAmount = this.playerMapper.selectNewChargeAmountSum(query);
			} else {
				lastAmount = this.playerMapper.selectContentNewChargeAmountSum(query);
			}
			resultMap.put("columnList", hoursList);
			resultMap.put("weakList", dataList);
			resultMap.put("lastWeakList", lastDataList);
			resultMap.put("maxAmount", maxAmount);
			resultMap.put("amount", amount);
			resultMap.put("lastAmount", lastAmount);
			if (lastAmount.intValue() != 0) {
				resultMap.put("ratio", amount.subtract(lastAmount).divide(lastAmount,2, BigDecimal.ROUND_HALF_UP));
			} else {
				resultMap.put("ratio", "0");
			}

			// 获取周和月份
		} else if (type == 1 || type == 2) {
			List<String> dateList = null;
			if (type == 1) {
				dateList = dateUtils.getWeakDayList();
			} else {
				dateList = dateUtils.getMonthDayList();
			}
			query.put("date", "%Y-%m-%d");
			query.put("startTime", dateList.get(0));
			query.put("endTime", dateList.get(dateList.size() - 1));
			List<Map<String, Object>> mapList;
			if (selectType == 0) {
				mapList = this.playerMapper.selectNewChargeAmount(query);
			} else {
				mapList = this.playerMapper.selectContentNewChargeAmount(query);
			}

			// 获取本周或本月数据
			List<BigDecimal> dataList = new ArrayList<>();
			for (String date : dateList) {
				boolean flag = true;
				for (Map<String, Object> map : mapList) {
					if (date.equals(map.get("date"))) {
						dataList.add((BigDecimal) map.get("amount"));
						flag = false;
					}
				}
				if (flag) {
					dataList.add(BigDecimal.ZERO);
				}
			}
			// 获取本周或本月总额
			// 获取最大值
			BigDecimal amount;
			BigDecimal maxAmount;
			if (selectType == 0) {
				amount = this.playerMapper.selectNewChargeAmountSum(query);
				maxAmount = this.playerMapper.selectNewChargeAmountMax(query);
			} else {
				amount = this.playerMapper.selectContentNewChargeAmountSum(query);
				maxAmount = this.playerMapper.selectContentNewChargeAmountMax(query);
			}

			// 获取上周或上月数据
			if (type == 1) {
				dateList = dateUtils.getLastWeakDayList();
			} else {
				dateList = dateUtils.getLastMonthDayList();
			}
			query.put("startTime", dateList.get(0));
			query.put("endTime", dateList.get(dateList.size() - 1));

			if (selectType == 0) {
				mapList = this.playerMapper.selectNewChargeAmount(query);
			} else {
				mapList = this.playerMapper.selectContentNewChargeAmount(query);
			}
			List<BigDecimal> lastDataList = new ArrayList<>();
			for (String date : dateList) {
				boolean flag = true;
				for (Map<String, Object> map : mapList) {
					if (date.equals(map.get("date"))) {
						lastDataList.add((BigDecimal) map.get("amount"));
						flag = false;
					}
				}
				if (flag) {
					lastDataList.add(BigDecimal.ZERO);
				}
			}
			BigDecimal lastAmount;
			if (selectType == 0) {
				lastAmount = this.playerMapper.selectNewChargeAmountSum(query);
			} else {
				lastAmount = this.playerMapper.selectContentNewChargeAmountSum(query);
			}

			if (type == 1) {
				resultMap.put("columnList", dateUtils.getWeakDayDayList());
			} else if (type == 2) {
				resultMap.put("columnList", dateUtils.getMonthDayDayList());
			} else {
				resultMap.put("columnList", dateList);
			}
			resultMap.put("weakList", dataList);
			resultMap.put("lastWeakList", lastDataList);
			resultMap.put("maxAmount", maxAmount);
			resultMap.put("amount", amount);
			resultMap.put("lastAmount", lastAmount);
			if (lastAmount.intValue() != 0) {
				resultMap.put("ratio", amount.subtract(lastAmount).divide(lastAmount,2, BigDecimal.ROUND_HALF_UP));
			} else {
				resultMap.put("ratio", "0");
			}
		}
		return resultMap;
	}

	/**
	 * 查询充值分析
	 *
	 * @param type       0 日 1 周 2 月
	 * @param list
	 * @param selectType 0查询推广类，1查询内容类
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectRechargeAnalysis(int type, List<String> list, int selectType) throws Exception {
		// 返回的对象
		Map<String, Object> resultMap = new HashMap<>();
		Map<String, Object> query = new HashMap<>();
		query.put("list", list);

		// 时间工具类
		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			query.put("date", "%Y-%m-%d %H");
			String[] hoursList = dateUtils.hoursList;

			// 获取今日新用户充值数据
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String date = sdf.format(new Date());
			query.put("startTime", date);
			query.put("endTime", date);
			query.put("queryType", 0);
			List<Map<String, Object>> mapList;
			if (selectType == 0) {
				mapList = this.playerMapper.selectNewChargeAmount(query);
			} else {
				mapList = this.playerMapper.selectContentNewChargeAmount(query);
			}
			List<String> dataList = new ArrayList<>();
			getDayData(hoursList, mapList, dataList);

			// 获取今日总额
			BigDecimal amount;
			if (selectType == 0) {
				amount = this.playerMapper.selectNewChargeAmountSum(query);
			} else {
				amount = this.playerMapper.selectContentNewChargeAmountSum(query);
			}
			// 获取今日累充数据
			List<String> cumulativeDataList = new ArrayList<>();
			query.put("queryType", 1);
			if (selectType == 0) {
				mapList = this.playerMapper.selectNewChargeAmount(query);
			} else {
				mapList = this.playerMapper.selectContentNewChargeAmount(query);
			}
			getDayData(hoursList, mapList, cumulativeDataList);

			// 获取昨日新充金额
			String yesterday = dateUtils.getYesterday();
			query.put("startTime", yesterday);
			query.put("endTime", yesterday);
			query.put("queryType", 0);
			BigDecimal lastAmount;
			if (selectType == 0) {
				lastAmount = this.playerMapper.selectNewChargeAmountSum(query);
			} else {
				lastAmount = this.playerMapper.selectContentNewChargeAmountSum(query);
			}
			resultMap.put("columnList", hoursList);
			resultMap.put("newChargeList", dataList);
			resultMap.put("tiredAnFullList", cumulativeDataList);
			resultMap.put("amount", amount);
			resultMap.put("lastAmount", lastAmount);
			if (lastAmount.intValue() != 0) {
				resultMap.put("ratio", amount.subtract(lastAmount).divide(lastAmount,2, BigDecimal.ROUND_HALF_UP));
			} else {
				resultMap.put("ratio", "0");
			}
		} else if (type == 1 || type == 2) {
			List<String> dateList = null;
			if (type == 1) {
				dateList = dateUtils.getWeakDayList();
			} else {
				dateList = dateUtils.getMonthDayList();
			}
			query.put("date", "%Y-%m-%d");

			// 获取本周或本月数据
			List<String> dataList = new ArrayList<>();
			query.put("startTime", dateList.get(0));
			query.put("endTime", dateList.get(dateList.size() - 1));
			query.put("queryType", 0);
			List<Map<String, Object>> mapList;
			if (selectType == 0) {
				mapList = this.playerMapper.selectNewChargeAmount(query);
			} else {
				mapList = this.playerMapper.selectContentNewChargeAmount(query);
			}
			getWeakMonthData(dateList, mapList, dataList);

			// 获取本周或本月总额
			BigDecimal amount;
			if (selectType == 0) {
				amount = this.playerMapper.selectNewChargeAmountSum(query);
			} else {
				amount = this.playerMapper.selectContentNewChargeAmountSum(query);
			}

			// 获取本周或本月累充数据
			query.put("queryType", 1);
			if (selectType == 0) {
				mapList = this.playerMapper.selectNewChargeAmount(query);
			} else {
				mapList = this.playerMapper.selectContentNewChargeAmount(query);
			}
			List<String> cumulativeDataList = new ArrayList<>();
			getWeakMonthData(dateList, mapList, cumulativeDataList);

			// 获取上周或上月新充金额
			if (type == 1) {
				dateList = dateUtils.getLastWeakDayList();
			} else {
				dateList = dateUtils.getLastMonthDayList();
			}
			query.put("startTime", dateList.get(0));
			query.put("endTime", dateList.get(dateList.size() - 1));
			query.put("queryType", 0);
			BigDecimal lastAmount;
			if (selectType == 0) {
				lastAmount = this.playerMapper.selectNewChargeAmountSum(query);
			} else {
				lastAmount = this.playerMapper.selectContentNewChargeAmountSum(query);
			}

			if (type == 1) {
				resultMap.put("columnList", dateUtils.getWeakDayDayList());
			} else if (type == 2) {
				resultMap.put("columnList", dateUtils.getMonthDayDayList());
			} else {
				resultMap.put("columnList", dateList);
			}
			resultMap.put("newChargeList", dataList);
			resultMap.put("tiredAnFullList", cumulativeDataList);
			resultMap.put("amount", amount);
			resultMap.put("lastAmount", lastAmount);
			if (lastAmount.intValue() != 0) {
				resultMap.put("ratio", amount.subtract(lastAmount).divide(lastAmount,2, BigDecimal.ROUND_HALF_UP));
			} else {
				resultMap.put("ratio", "0");
			}
		}
		return resultMap;
	}

	/**
	 * 查询任务发布数量
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Integer selectTaskReleaseNums(List<String> list) throws Exception {
		return this.playerMapper.selectTaskReleaseNums(list);
	}

	/**
	 * 查询派单任务
	 *
	 * @param type 0 日 1 周 2 月
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectAssignmentTask(int type, List<String> list) throws Exception {
		// 返回的对象
		Map<String, Object> resultMap = new HashMap<>();
		Map<String, Object> query = new HashMap<>();
		query.put("list", list);

		// 时间工具类
		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			query.put("date", "%Y-%m-%d %H");
			String[] hoursList = dateUtils.hoursList;

			// 获取今日新增任务数量、完成任务数量、未完成任务数量
			String date = dateUtils.getToday();
			query.put("startTime", date);
			query.put("endTime", date);

			// 查询新增任务，查询完成任务，查询未完成任务
			List<Map<String, Object>> newTaskss = this.playerMapper.selectNewTasks(query);
			List<Map<String, Object>> finishTheTasks = this.playerMapper.selectFinishTheTask(query);
			List<Map<String, Object>> incompleteTasks = this.playerMapper.selectIncompleteTask(query);

			List<String> newTasksList = new ArrayList<>();
			List<String> finishTheTaskList = new ArrayList<>();
			List<String> incompleteTaskList = new ArrayList<>();

			getDayData(hoursList, newTaskss, newTasksList);
			getDayData(hoursList, finishTheTasks, finishTheTaskList);
			getDayData(hoursList, incompleteTasks, incompleteTaskList);

			// 获取今日新增任务数量
			Integer todayNewTasksNumber = this.playerMapper.selectNewTasksNumber(query);
			// 获取昨日新增任务数量
			date = dateUtils.getYesterday();
			query.put("startTime", date);
			query.put("endTime", date);
			Integer yesterdayNewTasksNumber = this.playerMapper.selectNewTasksNumber(query);

			resultMap.put("columnList", hoursList);
			resultMap.put("newList", newTasksList);
			resultMap.put("finishList", finishTheTaskList);
			resultMap.put("incompleteList", incompleteTaskList);
			resultMap.put("numbers", todayNewTasksNumber);
			resultMap.put("lastNumbers", yesterdayNewTasksNumber);
			resultMap.put("newNumbers", todayNewTasksNumber - yesterdayNewTasksNumber);
		} else if (type == 1 || type == 2) {
			query.put("date", "%Y-%m-%d");
			List<String> columns;
			if (type == 1) {
				columns = dateUtils.getWeakDayList();
			} else {
				columns = dateUtils.getMonthDayList();
			}

			// 获取本周或者本月新增任务数量、完成任务数量、未完成任务数量
			query.put("startTime", columns.get(0));
			query.put("endTime", columns.get(columns.size() - 1));

			// 查询新增任务，查询完成任务，查询未完成任务
			List<Map<String, Object>> newTaskss = this.playerMapper.selectNewTasks(query);
			List<Map<String, Object>> finishTheTasks = this.playerMapper.selectFinishTheTask(query);
			List<Map<String, Object>> incompleteTasks = this.playerMapper.selectIncompleteTask(query);

			List<String> newTasksList = new ArrayList<>();
			List<String> finishTheTaskList = new ArrayList<>();
			List<String> incompleteTaskList = new ArrayList<>();

			getWeakMonthData(columns, newTaskss, newTasksList);
			getWeakMonthData(columns, finishTheTasks, finishTheTaskList);
			getWeakMonthData(columns, incompleteTasks, incompleteTaskList);

			// 获取本周或者本月新增任务数量
			Integer newTasksNumber = this.playerMapper.selectNewTasksNumber(query);
			// 获取上周或者上月新增任务数量
			if (type == 1) {
				columns = dateUtils.getLastWeakDayList();
			} else {
				columns = dateUtils.getLastMonthDayList();
			}
			query.put("startTime", columns.get(0));
			query.put("endTime", columns.get(columns.size() - 1));
			Integer lastNewTasksNumber = this.playerMapper.selectNewTasksNumber(query);

			if (type == 1) {
				resultMap.put("columnList", dateUtils.getWeakDayDayList());
			} else if (type == 2) {
				resultMap.put("columnList", dateUtils.getMonthDayDayList());
			} else {
				resultMap.put("columnList", columns);
			}
			resultMap.put("newList", newTasksList);
			resultMap.put("finishList", finishTheTaskList);
			resultMap.put("incompleteList", incompleteTaskList);
			resultMap.put("numbers", newTasksNumber);
			resultMap.put("lastNumbers", lastNewTasksNumber);
			resultMap.put("newNumbers", newTasksNumber - lastNewTasksNumber);
		}
		return resultMap;
	}

	/**
	 * 查询业务员数量
	 *
	 * @param type 0 日 1 周 2 月 3 季 4 年
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectSalesmenNumber(int type, List<String> list) throws Exception {
		// 返回的对象
		Map<String, Object> resultMap = new HashMap<>();
		List<String> columns = new ArrayList<>();
		List<String> dataList = new ArrayList<>();
		Integer number = 0;
		Integer lastNumber = 0;

		Map<String, Object> query = new HashMap<>();
		query.put("list", list);

		// 时间工具类
		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			String today = dateUtils.getToday();
			// 按小时查询
			String[] dateList = dateUtils.hoursList;
			columns = Arrays.asList(dateList);
			for (String date : dateList) {
				query.put("date", today + " " + date + ":00");
				Integer number1 = this.playerMapper.selectSalesmenNumber(query);
				dataList.add(number1 + "");
			}

			// 查询今日业务员人数
			query.put("date", today + " 23:59:59");
			number = this.playerMapper.selectSalesmenNumber(query);
			// 查询昨日业务员人数
			query.put("date", dateUtils.getYesterday() + " 23:59:59");
			lastNumber = this.playerMapper.selectSalesmenNumber(query);

		} else if (type == 1 || type == 2) {
			List<String> dateList;
			if (type == 1) {
				dateList = dateUtils.getWeakDayList();
				columns = dateUtils.getWeakDayDayList();
			} else {
				dateList = dateUtils.getMonthDayList();
				columns = dateUtils.getMonthDayDayList();
			}

			for (String date : dateList) {
				query.put("date", date + " 23:59:59");
				Integer number1 = this.playerMapper.selectSalesmenNumber(query);
				dataList.add(number1 + "");
			}

			// 查询本周或者本月业务员人数
			query.put("date", dateList.get(dateList.size() - 1) + " 23:59:59");
			number = this.playerMapper.selectSalesmenNumber(query);

			// 查询昨日业务员人数
			if (type == 1) {
				dateList = dateUtils.getLastWeakDayList();
			} else {
				dateList = dateUtils.getLastMonthDayList();
			}
			query.put("date", dateList.get(dateList.size() - 1) + " 23:59:59");
			lastNumber = this.playerMapper.selectSalesmenNumber(query);

		} else if (type == 3) {
			int year = dateUtils.getYear();
			int[] ints = dateUtils.getQuarterStartEnd();

			List<String> dateList = new ArrayList<>();

			for (int i = ints[0]; i < ints[1] + 1; i++) {
				query.put("date", year + "-" + i + "-31" + " 23:59:59");
				Integer number1 = this.playerMapper.selectSalesmenNumber(query);
				dataList.add(number1 + "");
				dateList.add(year + "-" + i);
			}
			columns = dateList;

			int quarter = dateUtils.getQuarter();
			// 查询本季度业务员人数
			query.put("date", dateUtils.getQuarterEndTime(quarter) + " 23:59:59");
			number = this.playerMapper.selectSalesmenNumber(query);

			// 查询上季度业务员人数
			query.put("date", dateUtils.getQuarterEndTime(quarter) + " 23:59:59");
			lastNumber = this.playerMapper.selectSalesmenNumber(query);

		} else if (type == 4) {
			Calendar cal = Calendar.getInstance();
			int month = cal.get(Calendar.MONTH);
			int year = cal.get(Calendar.YEAR);

			List<String> dateList = new ArrayList<>();
			for (int i = 1; i <= month + 1; i++) {
				query.put("date", year + "-" + i + "-31" + " 23:59:59");
				Integer number1 = this.playerMapper.selectSalesmenNumber(query);
				dataList.add(number1 + "");
				dateList.add(year + "-" + i);
			}
			columns = dateList;

			// 查询今年业务员人数
			query.put("date", year + "-12-31" + " 23:59:59");
			number = this.playerMapper.selectSalesmenNumber(query);

			// 查询去年业务员人数
			query.put("date", year - 1 + "-12-31" + " 23:59:59");
			lastNumber = this.playerMapper.selectSalesmenNumber(query);
		}

		resultMap.put("columnList", columns);
		resultMap.put("rowList", dataList);
		resultMap.put("number", number);
		resultMap.put("lastNumber", lastNumber);
		resultMap.put("addNumber", number - lastNumber);
		return resultMap;
	}

	/**
	 * 查询业务员数量明细
	 *
	 * @param date
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectSalesmenDetailed(String date, List<String> list) throws Exception {
		Map<String, Object> resultMap = new HashMap<>();

		Map<String, Object> query = new HashMap<>();
		query.put("list", list);

		// 查询今日数据
		query.put("date", date + "  23:59:59");
		Integer number = this.playerMapper.selectSalesmenNumber(query);

		// 查询昨天的数据
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date1 = sdf.parse(date);
		Calendar cal = Calendar.getInstance();
		cal.setTime(date1);
		cal.add(Calendar.DATE, -1);
		date = sdf.format(cal.getTime());
		query.put("date", date + "  23:59:59");
		Integer lastNumber = this.playerMapper.selectSalesmenNumber(query);

		resultMap.put("number", number);
		resultMap.put("lastNumber", lastNumber);
		resultMap.put("add", number - lastNumber);
		return resultMap;
	}


	/**
	 * 查询主播数量
	 *
	 * @param type 0 日 1 周 2 月 3 季 4 年
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectAnchorNumber(int type, List<String> list) throws Exception {
		// 返回的对象
		Map<String, Object> resultMap = new HashMap<>();
		List<String> columns = new ArrayList<>();
		List<String> dataList = new ArrayList<>();
		Integer number = 0;
		Integer lastNumber = 0;

		Map<String, Object> query = new HashMap<>();
		query.put("list", list);

		// 时间工具类
		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			String today = dateUtils.getToday();
			// 按小时查询
			String[] dateList = dateUtils.hoursList;
			columns = Arrays.asList(dateList);
			for (String date : dateList) {
				query.put("date", today + " " + date + ":00");
				Integer number1 = this.playerMapper.selectAnchorNumber(query);
				dataList.add(number1 + "");
			}

			// 查询今日业务员人数
			query.put("date", today + " 23:59:59");
			number = this.playerMapper.selectAnchorNumber(query);
			// 查询昨日业务员人数
			query.put("date", dateUtils.getYesterday() + " 23:59:59");
			lastNumber = this.playerMapper.selectAnchorNumber(query);

		} else if (type == 1 || type == 2) {
			List<String> dateList;
			if (type == 1) {
				dateList = dateUtils.getWeakDayList();
				columns = dateUtils.getWeakDayDayList();
			} else {
				dateList = dateUtils.getMonthDayList();
				columns = dateUtils.getMonthDayDayList();
			}

			for (String date : dateList) {
				query.put("date", date + " 23:59:59");
				Integer number1 = this.playerMapper.selectAnchorNumber(query);
				dataList.add(number1 + "");
			}

			// 查询本周或者本月业务员人数
			query.put("date", dateList.get(dateList.size() - 1) + " 23:59:59");
			number = this.playerMapper.selectAnchorNumber(query);

			// 查询昨日业务员人数
			if (type == 1) {
				dateList = dateUtils.getLastWeakDayList();
			} else {
				dateList = dateUtils.getLastMonthDayList();
			}
			query.put("date", dateList.get(dateList.size() - 1) + " 23:59:59");
			lastNumber = this.playerMapper.selectAnchorNumber(query);

		} else if (type == 3) {
			int year = dateUtils.getYear();
			int[] ints = dateUtils.getQuarterStartEnd();

			List<String> dateList = new ArrayList<>();

			for (int i = ints[0]; i < ints[1] + 1; i++) {
				query.put("date", year + "-" + i + "-31" + " 23:59:59");
				Integer number1 = this.playerMapper.selectAnchorNumber(query);
				dataList.add(number1 + "");
				dateList.add(year + "-" + i);
			}
			columns = dateList;

			int quarter = dateUtils.getQuarter();
			// 查询本季度业务员人数
			query.put("date", dateUtils.getQuarterEndTime(quarter) + " 23:59:59");
			number = this.playerMapper.selectAnchorNumber(query);

			// 查询上季度业务员人数
			query.put("date", dateUtils.getQuarterEndTime(quarter) + " 23:59:59");
			lastNumber = this.playerMapper.selectAnchorNumber(query);

		} else if (type == 4) {
			Calendar cal = Calendar.getInstance();
			int month = cal.get(Calendar.MONTH);
			int year = cal.get(Calendar.YEAR);

			List<String> dateList = new ArrayList<>();
			for (int i = 1; i <= month + 1; i++) {
				query.put("date", year + "-" + i + "-31" + " 23:59:59");
				Integer number1 = this.playerMapper.selectAnchorNumber(query);
				dataList.add(number1 + "");
				dateList.add(year + "-" + i);
			}
			columns = dateList;

			// 查询今年业务员人数
			query.put("date", year + "-12-31" + " 23:59:59");
			number = this.playerMapper.selectAnchorNumber(query);

			// 查询去年业务员人数
			query.put("date", year - 1 + "-12-31" + " 23:59:59");
			lastNumber = this.playerMapper.selectAnchorNumber(query);
		}

		resultMap.put("columnList", columns);
		resultMap.put("rowList", dataList);
		resultMap.put("number", number);
		resultMap.put("lastNumber", lastNumber);
		resultMap.put("addNumber", number - lastNumber);
		return resultMap;
	}

	/**
	 * 查询主播数量明细
	 *
	 * @param date
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectAnchorDetailed(String date, List<String> list) throws Exception {
		Map<String, Object> resultMap = new HashMap<>();

		Map<String, Object> query = new HashMap<>();
		query.put("list", list);

		// 查询今日数据
		query.put("date", date + "  23:59:59");
		Integer number = this.playerMapper.selectAnchorNumber(query);

		// 查询昨天的数据
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date1 = sdf.parse(date);
		Calendar cal = Calendar.getInstance();
		cal.setTime(date1);
		cal.add(Calendar.DATE, -1);
		date = sdf.format(cal.getTime());
		query.put("date", date + "  23:59:59");
		Integer lastNumber = this.playerMapper.selectAnchorNumber(query);

		resultMap.put("number", number);
		resultMap.put("lastNumber", lastNumber);
		resultMap.put("add", number - lastNumber);
		return resultMap;
	}

	/**
	 * 查询新增设备数量、新用户充值数、优质用户数、充值用户、累计充值额度
	 *
	 * @param type       0 日 1 周 2 月 3 季 4 年
	 * @param list
	 * @param selectType 0 新增设备数量 1 新用户充值数 2 优质用户数 3 充值用户 4 累计充值额度
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectAddEquipmentNumber(int type, List<String> list, int selectType) throws Exception {
		// 返回的对象
		Map<String, Object> resultMap = new HashMap<>();
		List<String> columns = new ArrayList<>();
		List<String> dataList = new ArrayList<>();
		BigDecimal number = BigDecimal.ZERO;
		BigDecimal lastNumber = BigDecimal.ZERO;

		// 封装查询条件
		Map<String, Object> query = new HashMap<>();
		Map<String, Object> lastQuery = new HashMap<>();
		query.put("list", list);
		lastQuery.put("list", list);
		// 时间工具类
		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			query.put("date", "%Y-%m-%d %H");
			lastQuery.put("date", "%Y-%m-%d %H");
			String[] hoursList = dateUtils.hoursList;
			columns = Arrays.asList(hoursList);

			// 获取今日新增设备数量
			String date = dateUtils.getToday();
			query.put("startTime", date);
			query.put("endTime", date);
			List<Map<String, Object>> mapList;
			if (selectType == 0) {
				mapList = this.playerMapper.selectAddEquipmentNumber(query);
			} else if (selectType == 1) {
				mapList = this.playerMapper.selectNewUserRecharge(query);
			} else if (selectType == 2) {
				mapList = this.playerMapper.selectHighQualityUser(query);
			} else if (selectType == 3) {
				mapList = this.playerMapper.selectRechargeUser(query);
			} else if(selectType == 4){
				mapList = this.playerMapper.selectTiredAndFull(query);
			}else {
				mapList = this.playerMapper.selectAddSalesmenNumber(query);
			}
			getDayData(hoursList, mapList, dataList);

			// 查询今日新增设备总数 、昨日新增设备总数
			date = dateUtils.getYesterday();
			lastQuery.put("startTime", date);
			lastQuery.put("endTime", date);
			if (selectType == 0) {
				number = new BigDecimal(this.playerMapper.selectAddEquipmentNumberCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectAddEquipmentNumberCount(lastQuery));
			} else if (selectType == 1) {
				number = new BigDecimal(this.playerMapper.selectNewUserRechargeCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectNewUserRechargeCount(lastQuery));
			} else if (selectType == 2) {
				number = new BigDecimal(this.playerMapper.selectHighQualityUserCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectHighQualityUserCount(lastQuery));
			} else if (selectType == 3) {
				number = new BigDecimal(this.playerMapper.selectRechargeUserCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectRechargeUserCount(lastQuery));
			} else if (selectType == 4) {
				number = this.playerMapper.selectTiredAndFullCount(query);
				lastNumber = this.playerMapper.selectTiredAndFullCount(lastQuery);
			}else {
				number = new BigDecimal(this.playerMapper.selectAddSalesmenNumberCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectAddSalesmenNumberCount(lastQuery));
			}

		} else if (type == 1 || type == 2) {
			query.put("date", "%Y-%m-%d");
			lastQuery.put("date", "%Y-%m-%d");
			List<String> dateList;
			if (type == 1) {
				dateList = dateUtils.getWeakDayList();
				columns = dateList;
			} else {
				dateList = dateUtils.getMonthDayList();
				columns = dateUtils.getMonthDayDayList();
			}

			// 获取本周或者本月新增设备数量
			query.put("startTime", dateList.get(0));
			query.put("endTime", dateList.get(dateList.size() - 1));
			List<Map<String, Object>> mapList;
			if (selectType == 0) {
				mapList = this.playerMapper.selectAddEquipmentNumber(query);
			} else if (selectType == 1) {
				mapList = this.playerMapper.selectNewUserRecharge(query);
			} else if (selectType == 2) {
				mapList = this.playerMapper.selectHighQualityUser(query);
			} else if (selectType == 3) {
				mapList = this.playerMapper.selectRechargeUser(query);
			} else if (selectType == 4){
				mapList = this.playerMapper.selectTiredAndFull(query);
			}else {
				mapList = this.playerMapper.selectAddSalesmenNumber(query);
			}
			getWeakMonthData(dateList, mapList, dataList);

			// 查询本周或者本月新增设备总数 、上周或者上月新增设备总数
			if (type == 1) {
				dateList = dateUtils.getLastWeakDayList();
			} else {
				dateList = dateUtils.getLastMonthDayList();
			}
			lastQuery.put("startTime", dateList.get(0));
			lastQuery.put("endTime", dateList.get(dateList.size() - 1));
			if (selectType == 0) {
				number = new BigDecimal(this.playerMapper.selectAddEquipmentNumberCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectAddEquipmentNumberCount(lastQuery));
			} else if (selectType == 1) {
				number = new BigDecimal(this.playerMapper.selectNewUserRechargeCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectNewUserRechargeCount(lastQuery));
			} else if (selectType == 2) {
				number = new BigDecimal(this.playerMapper.selectHighQualityUserCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectHighQualityUserCount(lastQuery));
			} else if (selectType == 3) {
				number = new BigDecimal(this.playerMapper.selectRechargeUserCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectRechargeUserCount(lastQuery));
			} else if (selectType == 4) {
				number = this.playerMapper.selectTiredAndFullCount(query);
				lastNumber = this.playerMapper.selectTiredAndFullCount(lastQuery);
			}else {
				number = new BigDecimal(this.playerMapper.selectAddSalesmenNumberCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectAddSalesmenNumberCount(lastQuery));
			}

		} else if (type == 3 || type == 4) {
			query.put("date", "%Y-%m");
			lastQuery.put("date", "%Y-%m");
			int year = dateUtils.getYear();
			int[] ints = dateUtils.getQuarterStartEnd();

			List<String> dateList = new ArrayList<>();
			if (type == 3) {
				for (int i = ints[0]; i < ints[1] + 1; i++) {
					dateList.add(year + "-" + i);
				}
				// 获取季度新增设备数量
				query.put("startTime", dateUtils.getCurrentQuarterStartTime());
				query.put("endTime", dateUtils.getCurrentQuarterEndTime());
			} else {
				for (int i = 1; i < 13; i++) {
					dateList.add(year + "-" + i);
				}
				// 获取年度度新增设备数量
				query.put("startTime", dateUtils.getCurrentYearStartTime());
				query.put("endTime", dateUtils.getCurrentYearEndTime());
			}
			columns = dateList;

			List<Map<String, Object>> mapList;
			if (selectType == 0) {
				mapList = this.playerMapper.selectAddEquipmentNumber(query);
			} else if (selectType == 1) {
				mapList = this.playerMapper.selectNewUserRecharge(query);
			} else if (selectType == 2) {
				mapList = this.playerMapper.selectHighQualityUser(query);
			} else if (selectType == 3) {
				mapList = this.playerMapper.selectRechargeUser(query);
			} else if (selectType == 4){
				mapList = this.playerMapper.selectTiredAndFull(query);
			} else {
				mapList = this.playerMapper.selectAddSalesmenNumber(query);
			}
			getWeakMonthData(dateList, mapList, dataList);

			// 查询本季、本年度度新增设备总数、上季、上年度度新增设备总数
			if (type == 3) {
				lastQuery.put("startTime", dateUtils.getLastQuarterStartTime());
				lastQuery.put("endTime", dateUtils.getLastQuarterEndTime());
			} else {
				query.put("startTime", dateUtils.getLastYearStartTime());
				query.put("endTime", dateUtils.getLastYearEndTime());
			}
			if (selectType == 0) {
				number = new BigDecimal(this.playerMapper.selectAddEquipmentNumberCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectAddEquipmentNumberCount(lastQuery));
			} else if (selectType == 1) {
				number = new BigDecimal(this.playerMapper.selectNewUserRechargeCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectNewUserRechargeCount(lastQuery));
			} else if (selectType == 2) {
				number = new BigDecimal(this.playerMapper.selectHighQualityUserCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectHighQualityUserCount(lastQuery));
			} else if (selectType == 3) {
				number = new BigDecimal(this.playerMapper.selectRechargeUserCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectRechargeUserCount(lastQuery));
			} else if (selectType == 4) {
				number = this.playerMapper.selectTiredAndFullCount(query);
				lastNumber = this.playerMapper.selectTiredAndFullCount(lastQuery);
			}else {
				number = new BigDecimal(this.playerMapper.selectAddSalesmenNumberCount(query));
				lastNumber = new BigDecimal(this.playerMapper.selectAddSalesmenNumberCount(lastQuery));
			}

		}
		resultMap.put("columnList", columns);
		resultMap.put("rowList", dataList);
		resultMap.put("number", number);
		resultMap.put("lastNumber", lastNumber);
		resultMap.put("addNumber", number.subtract(lastNumber));
		return resultMap;
	}

	/**
	 * 查询新增设备数量明细
	 *
	 * @param date
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectAddEquipmentNumberDetailed(String date, List<String> list, int selectType) throws Exception {
		Map<String, Object> resultMap = new HashMap<>();

		// 时间工具类
		DateUtils dateUtils = new DateUtils();

		Map<String, Object> query = new HashMap<>();
		query.put("list", list);

		// 查询今日数据
		query.put("startTime", date);
		query.put("endTime", date);
		BigDecimal number = BigDecimal.ZERO;
		if (selectType == 0) {
			number = new BigDecimal(this.playerMapper.selectAddEquipmentNumberCount(query));
		} else if (selectType == 1) {
			number = new BigDecimal(this.playerMapper.selectNewUserRechargeCount(query));
		} else if (selectType == 2) {
			number = new BigDecimal(this.playerMapper.selectHighQualityUserCount(query));
		} else if (selectType == 3) {
			number = new BigDecimal(this.playerMapper.selectRechargeUserCount(query));
		}  else if (selectType == 4) {
			number = this.playerMapper.selectTiredAndFullCount(query);
		}  else {
			number = new BigDecimal(this.playerMapper.selectAddSalesmenNumberCount(query));
		}

		// 查询昨天的数据
		date = dateUtils.getYesterday(date);
		query.put("startTime", date);
		query.put("endTime", date);
		BigDecimal lastNumber = BigDecimal.ZERO;
		if (selectType == 0) {
			lastNumber = new BigDecimal(this.playerMapper.selectAddEquipmentNumberCount(query));
		} else if (selectType == 1) {
			lastNumber = new BigDecimal(this.playerMapper.selectNewUserRechargeCount(query));
		} else if (selectType == 2) {
			lastNumber = new BigDecimal(this.playerMapper.selectHighQualityUserCount(query));
		} else if (selectType == 3) {
			lastNumber = new BigDecimal(this.playerMapper.selectRechargeUserCount(query));
		}  else if (selectType == 4) {
			number = this.playerMapper.selectTiredAndFullCount(query);
		}  else {
			lastNumber = new BigDecimal(this.playerMapper.selectAddSalesmenNumberCount(query));
		}
		resultMap.put("number", number);
		resultMap.put("lastNumber", lastNumber);
		if (lastNumber.compareTo(BigDecimal.ZERO) != 0) {
			resultMap.put("add", number.divide(lastNumber, 2, BigDecimal.ROUND_HALF_UP));
		} else {
			resultMap.put("add", 0);
		}
		return resultMap;
	}

	/**
	 * 查询公会任务汇总
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectTaskSummary(List<String> list) throws Exception {
		return playerMapper.selectTaskSummary(list);
	}

	/**
	 * 查询业务员逾期情况
	 *
	 * @param type
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public List<Map<String, Object>> selectSalesmanOverdue(int type, List<String> list) throws Exception {
		// 封装参数
		Map<String, Object> map = new HashMap<>();
		map.put("list", list);

		// 时间工具类
		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			map.put("startTime", dateUtils.getToday() + " 00:00:00");
			map.put("endTime", dateUtils.getToday() + " 23:59:59");
		} else if (type == 1) {
			map.put("startTime", dateUtils.getCurrentWeekDayStartTime() + " 00:00:00");
			map.put("endTime", dateUtils.getCurrentWeekDayEndTime() + " 23:59:59");
		} else {
			map.put("startTime", dateUtils.getCurrentMonthStartTime() + " 00:00:00");
			map.put("endTime", dateUtils.getCurrentMonthEndTime() + " 23:59:59");
		}
		return this.playerMapper.selectSalesmanOverdue(map);
	}

	/**
	 * 查询累计充值额度,根据时间查询
	 *
	 * @param type
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public BigDecimal selectRechargeUserAmountByDate(int type, List<String> list) throws Exception {
		// 封装参数
		Map<String, Object> map = new HashMap<>();
		map.put("list", list);

		// 时间工具类
		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			map.put("startTime", dateUtils.getToday() + " 00:00:00");
			map.put("endTime", dateUtils.getToday() + " 23:59:59");
		} else if (type == 2) {
			map.put("startTime", dateUtils.getCurrentMonthStartTime() + " 00:00:00");
			map.put("endTime", dateUtils.getCurrentMonthEndTime() + " 23:59:59");
		}
		return this.playerMapper.selectRechargeUserAmountByDate(map);
	}

	/**
	 * 查询用户充值信息
	 *
	 * @param type 0 日 1 周 2 月
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectUserRechargeStatistics(int type, List<String> list, int selectType) throws Exception {
		// 返回的对象
		Map<String, Object> resultMap = new HashMap<>();
		List<String> columnList = new ArrayList<>();
		List<String> dataList = new ArrayList<>();

		Map<String, Object> query = new HashMap<>();
		query.put("list", list);
		// 代表查询为累充
		query.put("queryType", 1);

		// 时间工具类
		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			query.put("date", "%Y-%m-%d %H");
			String[] hoursList = dateUtils.hoursList;
			columnList = Arrays.asList(hoursList);

			// 获取今日新用户充值数据
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String date = sdf.format(new Date());
			query.put("startTime", date);
			query.put("endTime", date);
			List<Map<String, Object>> mapList = this.playerMapper.selectNewChargeAmount(query);
			// 代表查询营收
			if (selectType == 0) {
				for (Map<String, Object> map : mapList) {
					BigDecimal amount = (BigDecimal) map.get("amount");
					map.put("amount", amount.multiply(new BigDecimal(0.3)));
				}
			}
			getDayData(hoursList, mapList, dataList);

		} else if (type == 1 || type == 2) {
			List<String> dateList = null;
			if (type == 1) {
				dateList = dateUtils.getWeakDayList();
				columnList = dateUtils.getWeakDayDayList();
			} else {
				dateList = dateUtils.getMonthDayList();
				columnList = dateUtils.getMonthDayDayList();
			}
			query.put("date", "%Y-%m-%d");

			// 获取本周或本月数据
			query.put("startTime", dateList.get(0));
			query.put("endTime", dateList.get(dateList.size() - 1));
			List<Map<String, Object>> mapList = this.playerMapper.selectNewChargeAmount(query);
			// 代表查询营收
			if (selectType == 0) {
				for (Map<String, Object> map : mapList) {
					BigDecimal amount = (BigDecimal) map.get("amount");
					map.put("amount", amount.multiply(new BigDecimal(0.3)));
				}
			}
			getWeakMonthData(dateList, mapList, dataList);
		}
		resultMap.put("columnList", columnList);
		resultMap.put("rowList", dataList);
		return resultMap;
	}

	/**
	 * 分页查询潜力用户
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	public BasePage<Map<String, Object>> selectPotentialUsersByPage(Map<String, Object> params, BasePage<Map<String, Object>> page) throws Exception {
		params.put("page", page);
		List<Map<String, Object>> list = this.playerMapper.selectPotentialUsersByPage(params);
		page.setResults(list);
		return page;
	}

	/**
	 * 分页查询优质用户
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	public BasePage<Map<String, Object>> selectHighQualityUsersByPage(Map<String, Object> params, BasePage<Map<String, Object>> page) throws Exception {
		params.put("page", page);
		List<Map<String, Object>> list = this.playerMapper.selectHighQualityUsersByPage(params);
		page.setResults(list);
		return page;
	}

	/**
	 * 分页查询主播转换率
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	public BasePage<Map<String, Object>> selectFlowPoolUsersByPage(Map<String, Object> params, BasePage<Map<String, Object>> page) throws Exception {
		params.put("page", page);
		List<Map<String, Object>> list = this.playerMapper.selectFlowPoolUsersByPage(params);
		page.setResults(list);
		return page;
	}

	/**
	 * 查询工会用户
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectUnionUsers(List<String> list) throws Exception {
		return this.playerMapper.selectUnionUsers(list);
	}

	/**
	 * 查询业务员排行榜
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public List<Map<String, Object>> selectSalesmanRanking(Map<String, Object> map) throws Exception {
		return this.playerMapper.selectSalesmanRanking(map);
	}

	/**
	 * 查询新增注册用户统计
	 *
	 * @param list 业务员id集合
	 * @param type 类型 0-日 1-周 2-月
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectNewRegisteredUsers(List<String> list, int type) throws Exception {
		// 返回的对象
		Map<String, Object> resultMap = new HashMap<>();
		List<String> columnList = new ArrayList<>();
		List<String> rowList = new ArrayList<>();
		List<String> rowList1 = new ArrayList<>();

		Map<String, Object> query = new HashMap<>();
		query.put("list", list);

		// 时间工具类
		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			query.put("date", "%Y-%m-%d %H");
			String[] hoursList = dateUtils.hoursList;
			columnList = Arrays.asList(hoursList);

			// 获取今日新用户充值数据
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String date = sdf.format(new Date());
			query.put("startTime", date);
			query.put("endTime", date);
			// 0代表查询为新增注册用户
			query.put("selectType", 0);
			List<Map<String, Object>> mapList = this.playerMapper.selectNewRegisteredUsers(query);
			getDayData(hoursList, mapList, rowList);

			// 1代表查询为新增有效注册用户
			query.put("selectType", 1);
			List<Map<String, Object>> mapList1 = this.playerMapper.selectNewRegisteredUsers(query);
			getDayData(hoursList, mapList1, rowList1);

		} else if (type == 1 || type == 2) {
			List<String> dateList = null;
			if (type == 1) {
				dateList = dateUtils.getWeakDayList();
				columnList = dateUtils.getWeakDayDayList();
			} else {
				dateList = dateUtils.getMonthDayList();
				columnList = dateUtils.getMonthDayDayList();
			}
			query.put("date", "%Y-%m-%d");

			// 获取本周或本月数据
			query.put("startTime", dateList.get(0));
			query.put("endTime", dateList.get(dateList.size() - 1));
			// 0代表查询为新增注册用户
			query.put("selectType", 0);
			List<Map<String, Object>> mapList = this.playerMapper.selectNewRegisteredUsers(query);
			getWeakMonthData(dateList, mapList, rowList);

			// 1代表查询为新增有效注册用户
			query.put("selectType", 1);
			List<Map<String, Object>> mapList1 = this.playerMapper.selectNewRegisteredUsers(query);
			getWeakMonthData(dateList, mapList1, rowList1);
		}
		resultMap.put("columnList", columnList);
		resultMap.put("addUserList", rowList);
		resultMap.put("effectiveUserList", rowList1);
		return resultMap;
	}

	/**
	 * 查询我的任务
	 *
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectMyMission(String userId) throws Exception {
		return this.playerMapper.selectMyMission(userId);
	}

	/**
	 * 查询任务统计
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectMyMissionByUserIds(List<String> list) throws Exception {
		return this.playerMapper.selectMyMissionByUserIds(list);
	}

	/**
	 * 查询累计充值额度总数
	 *
	 * @param list
	 * @param type
	 * @return
	 * @throws Exception
	 */
	public BigDecimal selectTiredAndFullCount(List<String> list, int type, int selectType) throws Exception {
		Map<String, Object> query = new HashMap<>();
		query.put("list", list);

		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			// 获取今日累计充值额度总数
			String date = dateUtils.getToday();
			query.put("startTime", date);
			query.put("endTime", date);
		} else if (type == 1 || type == 2) {
			List<String> dateList;
			if (type == 1) {
				dateList = dateUtils.getWeakDayList();
			} else {
				dateList = dateUtils.getMonthDayList();
			}

			// 获取本周或者本月累计充值额度总数
			query.put("startTime", dateList.get(0));
			query.put("endTime", dateList.get(dateList.size() - 1));
		} else if (type == 3 || type == 4) {
			int year = dateUtils.getYear();
			int[] ints = dateUtils.getQuarterStartEnd();

			List<String> dateList = new ArrayList<>();
			if (type == 3) {
				for (int i = ints[0]; i < ints[1]; i++) {
					dateList.add(year + "-" + i);
				}
				// 获取季度累计充值额度总数
				query.put("startTime", dateUtils.getCurrentQuarterStartTime());
				query.put("endTime", dateUtils.getCurrentQuarterEndTime());
			} else {
				for (int i = 1; i < 13; i++) {
					dateList.add(year + "-" + i);
				}
				// 获取年度度累计充值额度总数
				query.put("startTime", dateUtils.getCurrentYearStartTime());
				query.put("endTime", dateUtils.getCurrentYearEndTime());
			}
		}
		if (selectType == 0) {
			return this.playerMapper.selectTiredAndFullCount(query);
		} else {
			return this.playerMapper.selectContentTiredAndFullCount(query);
		}
	}

	/**
	 * 查询累计充值额度总数
	 *
	 * @param userId
	 * @param startTime
	 * @param endTime
	 * @return
	 * @throws Exception
	 */
	public BigDecimal selectTiredAndFullCount(String userId, String startTime, String endTime) throws Exception {
		Map<String, Object> query = new HashMap<>();

		ArrayList list = new ArrayList<String>();
		list.add(userId);
		query.put("list", list);
		query.put("startTime", startTime + " 00:00:00");
		query.put("endTime", endTime + " 23:59:59");
		return this.playerMapper.selectTiredAndFullCount(query);
	}

	/**
	 * 查询业务员下的当天新增注册玩家和有效玩家玩家
	 *
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectSalesmanPlayerNumber(String userId) throws Exception {
		return this.playerMapper.selectSalesmanPlayerNumber(userId);
	}

	/**
	 * 查询优质用户数
	 *
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public Integer selectHighQualityUsersNumber(String userId) throws Exception {
		return this.playerMapper.selectHighQualityUsersNumber(userId);
	}

	/**
	 * 查询d
	 *
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public Integer selectTodayRegisterNumber(String userId) throws Exception {
		return this.playerMapper.selectTodayRegisterNumber(userId);
	}

	/**
	 * 查询任务数量
	 *
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectTaskNumber(String userId) throws Exception {
		return this.playerMapper.selectTaskNumber(userId);
	}

	/**
	 * 查询排行第几
	 *
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public Integer selectRankingByCount(String userId, List<String> list) throws Exception {
		Integer rank = null;
		List<RankingListVO> rankingList = this.playerMapper.selectSalesmanRankingList(list);
		for (RankingListVO rankingListVO : rankingList) {
			if (rankingListVO.getId().equals(userId)) {
				rank = rankingListVO.getRank();
			}
		}
		if (rank == null) {
			rank = list.size() + 1;
		}
		return rank;
	}

	/**
	 * 查询维护任务和推广任务的对象
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public List<String> selectPromotionTaskMaintenanceTask(Map<String, Object> map) throws Exception {
		return this.playerMapper.selectPromotionTaskMaintenanceTask(map);
	}

	/**
	 * 查询充值玩家的数量
	 *
	 * @param anchorId
	 * @return
	 * @throws Exception
	 */
	public Integer selectRechargePlayerNumber(String anchorId) throws Exception {
		return this.playerMapper.selectRechargePlayerNumber(anchorId);
	}

	/**
	 * 查询访问玩家的数量
	 *
	 * @param anchorId
	 * @return
	 * @throws Exception
	 */
	public Integer selectVisitPlayerNumber(String anchorId) throws Exception {
		return this.playerMapper.selectVisitPlayerNumber(anchorId);
	}

	/**
	 * 查询主播的收益
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public BigDecimal selectAnchorProfit(Map<String, Object> map) throws Exception {
		return this.playerMapper.selectAnchorProfit(map);
	}

	/**
	 * 查询优质主播排行
	 *
	 * @return
	 * @throws Exception
	 */
	public List<RankingListVO> selectQualityAnchorRanking(Map<String, Object> map) throws Exception {
		return this.playerMapper.selectQualityAnchorRanking(map);
	}

	/**
	 * 查询工会排行
	 *
	 * @return
	 * @throws Exception
	 */
	public List<RankingListVO> selectLabourUnionRanking(List<String> list) throws Exception {
		return this.playerMapper.selectLabourUnionRanking(list);
	}

	/**
	 * 查询频道厅进入人数趋势
	 *
	 * @param type 0 日 1 周 2 月
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> selectVisitsNumber(int type, List<String> list) throws Exception {
		// 返回的对象
		Map<String, Object> resultMap = new HashMap<>();
		List<String> columnList = new ArrayList<>();
		List<String> dataList = new ArrayList<>();
		Integer newUsersNumber = 0;

		Map<String, Object> query = new HashMap<>();
		query.put("list", list);

		// 时间工具类
		DateUtils dateUtils = new DateUtils();
		if (type == 0) {
			query.put("date", "%Y-%m-%d %H");
			String[] hoursList = dateUtils.hoursList;
			columnList = Arrays.asList(hoursList);

			// 获取今日新用户充值数据
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String date = sdf.format(new Date());
			query.put("startTime", date);
			query.put("endTime", date);
			List<Map<String, Object>> mapList = this.playerMapper.selectVisitsNumber(query);
			getDayData(hoursList, mapList, dataList);
			newUsersNumber = this.playerMapper.selectNewUsersVisitsNumber(query);

		} else if (type == 1 || type == 2) {
			List<String> dateList = null;
			if (type == 1) {
				dateList = dateUtils.getWeakDayList();
				columnList = dateUtils.getWeakDayDayList();
			} else {
				dateList = dateUtils.getMonthDayList();
				columnList = dateUtils.getMonthDayDayList();
			}
			query.put("date", "%Y-%m-%d");

			// 获取本周或本月数据
			query.put("startTime", dateList.get(0));
			query.put("endTime", dateList.get(dateList.size() - 1));
			List<Map<String, Object>> mapList = this.playerMapper.selectVisitsNumber(query);
			getWeakMonthData(dateList, mapList, dataList);

			newUsersNumber = this.playerMapper.selectNewUsersVisitsNumber(query);
		}
		resultMap.put("columnList", columnList);
		resultMap.put("rowList", dataList);
		resultMap.put("newUsersNumber", newUsersNumber);
		return resultMap;
	}

	/**
	 * 查询公会用户消费TOP榜
	 *
	 * @return
	 * @throws Exception
	 */
	public List<RankingListVO> selectConsumptionRanking(Map<String, Object> map) throws Exception {
		return this.playerMapper.selectConsumptionRanking(map);
	}

	/**
	 * 查询访问用户数
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public Integer selectVisitsNumberByTime(Map<String, Object> map) throws Exception {
		return this.playerMapper.selectVisitsNumberByTime(map);
	}

	/**
	 * 查询充值用户数
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public Integer selectConsumeUserNum(Map<String, Object> map) throws Exception {
		return this.playerMapper.selectConsumeUserNum(map);
	}

	/**
	 * 分页查询私域流量池用户
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	public BasePage<Map<String, Object>> selectAnchorConversionRateByPage(Map<String, Object> params, BasePage<Map<String, Object>> page) throws Exception {
		params.put("page", page);
		List<Map<String, Object>> list = this.playerMapper.selectAnchorConversionRateByPage(params);
		page.setResults(list);
		return page;
	}

	/**
	 * 查询首次进房排行榜
	 *
	 * @return
	 * @throws Exception
	 */
	public List<RankingListVO> selectFirstGetintoHousingRanking(Map<String, Object> map) throws Exception {
		return this.playerMapper.selectFirstGetintoHousingRanking(map);
	}

	/**
	 * 查询转换率排行榜
	 *
	 * @return
	 * @throws Exception
	 */
	public List<RankingListVO> selectConversionRateRanking(Map<String, Object> map) throws Exception {
		return this.playerMapper.selectConversionRateRanking(map);
	}

	/**
	 * 查询主播排麦直播时长排行、主播个人直播时长排行
	 *
	 * @param timeType
	 * @param list
	 * @param type
	 * @return
	 * @throws Exception
	 */
	public List<Map<String, Object>> selectAnchorLiveTime(int timeType, List<String> list, int type) throws Exception {
		// 返回的对象
		List<Map<String, Object>> resultList = new ArrayList<>();

		Map<String, Object> query = new HashMap<>();
		query.put("list", list);
		query.put("type", type);

		// 时间工具类
		DateUtils dateUtils = new DateUtils();
		if (timeType == 0) {
			// 获取今日数据
			query.put("startTime", dateUtils.getToday());
			query.put("endTime", dateUtils.getToday());
			resultList = this.playerMapper.selectAnchorLiveTime(query);
		} else if (timeType == 1 || timeType == 2) {
			List<String> dateList = null;
			if (timeType == 1) {
				dateList = dateUtils.getWeakDayList();
			} else {
				dateList = dateUtils.getMonthDayList();
			}

			// 获取本周或本月数据
			query.put("startTime", dateList.get(0));
			query.put("endTime", dateList.get(dateList.size() - 1));
			resultList = this.playerMapper.selectAnchorLiveTime(query);
		}
		return resultList;
	}

	/**
	 * 查询自带粉排行
	 *
	 * @return
	 * @throws Exception
	 */
	public List<Map<String, Object>> selectAnchorByoFans(Map<String, Object> params) throws Exception {
		return this.playerMapper.selectAnchorByoFans(params);
	}


	/**
	 * 统计业务员推广主播数
	 *
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer countTaskAnchorNum(Map<String, Object> params) throws Exception {
		return this.playerMapper.countTaskAnchorNum(params);
	}


	/**
	 * 统计业务员推广主播数(定时)
	 *
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer countTaskAnchorNumTenantCode(Map<String, Object> params, String tenantCode) throws Exception {
		if (StringUtils.isNotEmpty(tenantCode)) {
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.countTaskAnchorNum(params);
	}

	/**
	 * 获取ltv
	 *
	 * @param map
	 * @return
	 */
	private BigDecimal getLtv(Map<String, Object> map) {
		long playerNum = (long) map.get("playerNum");
		BigDecimal amount = (BigDecimal) map.get("amount");
		if (playerNum != 0) {
			return amount.divide(new BigDecimal(playerNum), 2, BigDecimal.ROUND_HALF_UP);
		}
		return BigDecimal.ZERO;
	}

	public class DateUtils {

		// 日期格式化
		private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

		/**
		 * 今天日期
		 *
		 * @return
		 */
		public String getToday() {
			Calendar c = Calendar.getInstance();
			return sdf.format(c.getTime());
		}

		/**
		 * 获得年
		 *
		 * @return
		 */
		public Integer getYear() {
			Calendar c = Calendar.getInstance();
			return c.get(Calendar.YEAR);
		}

		/**
		 * 获得昨天的日期
		 *
		 * @return
		 */
		public String getYesterday() {
			Calendar c = Calendar.getInstance();
			try {
				c.add(Calendar.DATE, -1);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 获得昨天的日期
		 *
		 * @return
		 */
		public String getYesterday(String date) {
			Calendar cal = Calendar.getInstance();
			try {
				Date date1 = sdf.parse(date);
				cal.setTime(date1);
				cal.add(Calendar.DATE, -1);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(cal.getTime());
		}

		/**
		 * 获得本周的第一天，周一
		 *
		 * @return
		 */
		public String getCurrentWeekDayStartTime() {
			Calendar c = Calendar.getInstance();
			try {
				int dayofweek = c.get(Calendar.DAY_OF_WEEK);
				if(dayofweek==1){
					dayofweek+=7;
				}
				c.add(Calendar.DATE,2-dayofweek);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 获取季度
		 *
		 * @return
		 */
		public Integer getQuarter() {
			Calendar c = Calendar.getInstance();
			int quarter;
			int m = c.get(c.MONTH);
			if (m >= 1 && m <= 3) {
				quarter = 1;
			} else if (m >= 4 && m <= 6) {
				quarter = 2;
			} else if (m >= 7 && m <= 9) {
				quarter = 3;
			} else {
				quarter = 4;
			}
			return quarter;
		}

		/**
		 * 获取季度
		 *
		 * @return
		 */
		public int[] getQuarterStartEnd() {
			int[] ints = { 1, 4 };
			Calendar c = Calendar.getInstance();
			int m = c.get(c.MONTH);
			if (m >= 1 && m <= 3) {
				ints[0] = 1;
				ints[1] = 4;
			} else if (m >= 4 && m <= 6) {
				ints[0] = 4;
				ints[1] = 7;
			} else if (m >= 7 && m <= 9) {
				ints[0] = 7;
				ints[1] = 10;
			} else {
				ints[0] = 10;
				ints[1] = 13;
			}
			return ints;
		}

		/**
		 * 根据季度数获取结束时间
		 */
		public String getQuarterEndTime(int quarter) {
			Calendar end = Calendar.getInstance();
			if (quarter == 0) {
				end.add(Calendar.YEAR, -1);
			}
			try {
				if (quarter == 1) {
					end.set(Calendar.MONTH, 2);
					end.set(Calendar.DATE, 31);
				} else if (quarter == 2) {
					end.set(Calendar.MONTH, 5);
					end.set(Calendar.DATE, 30);
				} else if (quarter == 3) {
					end.set(Calendar.MONTH, 8);
					end.set(Calendar.DATE, 30);
				} else if (quarter == 4) {
					end.set(Calendar.MONTH, 11);
					end.set(Calendar.DATE, 31);
				}
				end.add(Calendar.DATE, 1);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(end.getTime());
		}

		/**
		 * 获得本周的最后一天，周日
		 *
		 * @return
		 */
		public String getCurrentWeekDayEndTime() {
			Calendar c = Calendar.getInstance();
			try {
				int dayofweek = c.get(Calendar.DAY_OF_WEEK);
				if(dayofweek==1){
					dayofweek+=7;
				}
				c.add(Calendar.DATE,2-dayofweek);
				c.add(Calendar.DAY_OF_WEEK,6);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 获得本月的开始时间
		 *
		 * @return
		 */
		public String getCurrentMonthStartTime() {
			Calendar c = Calendar.getInstance();
			try {
				c.set(Calendar.DATE, 1);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 本月的结束时间
		 *
		 * @return
		 */
		public String getCurrentMonthEndTime() {
			Calendar c = Calendar.getInstance();
			try {
				c.set(Calendar.DATE, 1);
				c.add(Calendar.MONTH, 1);
				c.add(Calendar.DATE, -1);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 当前年的开始时间
		 *
		 * @return
		 */
		public String getCurrentYearStartTime() {
			Calendar c = Calendar.getInstance();
			try {
				c.set(Calendar.MONTH, 0);
				c.set(Calendar.DATE, 1);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 当前年的结束时间
		 *
		 * @return
		 */
		public String getCurrentYearEndTime() {
			Calendar c = Calendar.getInstance();
			try {
				c.set(Calendar.MONTH, 11);
				c.set(Calendar.DATE, 31);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 去年的开始时间
		 *
		 * @return
		 */
		public String getLastYearStartTime() {
			Calendar c = Calendar.getInstance();
			try {
				c.add(Calendar.YEAR, -1);
				c.set(Calendar.MONTH, 0);
				c.set(Calendar.DATE, 1);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 去年的结束时间
		 *
		 * @return
		 */
		public String getLastYearEndTime() {
			Calendar c = Calendar.getInstance();
			try {
				c.add(Calendar.YEAR, -1);
				c.set(Calendar.MONTH, 11);
				c.set(Calendar.DATE, 31);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 当前季度的开始时间
		 *
		 * @return
		 */
		public String getCurrentQuarterStartTime() {
			Calendar c = Calendar.getInstance();
			int currentMonth = c.get(Calendar.MONTH) + 1;
			try {
				if (currentMonth >= 1 && currentMonth <= 3)
					c.set(Calendar.MONTH, 0);
				else if (currentMonth >= 4 && currentMonth <= 6)
					c.set(Calendar.MONTH, 3);
				else if (currentMonth >= 7 && currentMonth <= 9)
					c.set(Calendar.MONTH, 4);
				else if (currentMonth >= 10 && currentMonth <= 12)
					c.set(Calendar.MONTH, 9);
				c.set(Calendar.DATE, 1);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 当前季度的结束时间
		 *
		 * @return
		 */
		public String getCurrentQuarterEndTime() {
			Calendar c = Calendar.getInstance();
			int currentMonth = c.get(Calendar.MONTH) + 1;
			try {
				if (currentMonth >= 1 && currentMonth <= 3) {
					c.set(Calendar.MONTH, 2);
					c.set(Calendar.DATE, 31);
				} else if (currentMonth >= 4 && currentMonth <= 6) {
					c.set(Calendar.MONTH, 5);
					c.set(Calendar.DATE, 30);
				} else if (currentMonth >= 7 && currentMonth <= 9) {
					c.set(Calendar.MONTH, 8);
					c.set(Calendar.DATE, 30);
				} else if (currentMonth >= 10 && currentMonth <= 12) {
					c.set(Calendar.MONTH, 11);
					c.set(Calendar.DATE, 31);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 上个季度的开始时间
		 *
		 * @return
		 */
		public String getLastQuarterStartTime() {
			Calendar c = Calendar.getInstance();
			c.add(Calendar.MONTH, -4);
			int currentMonth = c.get(Calendar.MONTH) + 1;
			try {
				if (currentMonth >= 1 && currentMonth <= 3)
					c.set(Calendar.MONTH, 0);
				else if (currentMonth >= 4 && currentMonth <= 6)
					c.set(Calendar.MONTH, 3);
				else if (currentMonth >= 7 && currentMonth <= 9)
					c.set(Calendar.MONTH, 4);
				else if (currentMonth >= 10 && currentMonth <= 12)
					c.set(Calendar.MONTH, 9);
				c.set(Calendar.DATE, 1);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 上个季度的结束时间
		 *
		 * @return
		 */
		public String getLastQuarterEndTime() {
			Calendar c = Calendar.getInstance();
			c.add(Calendar.MONTH, -4);
			int currentMonth = c.get(Calendar.MONTH) + 1;
			try {
				if (currentMonth >= 1 && currentMonth <= 3) {
					c.set(Calendar.MONTH, 2);
					c.set(Calendar.DATE, 31);
				} else if (currentMonth >= 4 && currentMonth <= 6) {
					c.set(Calendar.MONTH, 5);
					c.set(Calendar.DATE, 30);
				} else if (currentMonth >= 7 && currentMonth <= 9) {
					c.set(Calendar.MONTH, 8);
					c.set(Calendar.DATE, 30);
				} else if (currentMonth >= 10 && currentMonth <= 12) {
					c.set(Calendar.MONTH, 11);
					c.set(Calendar.DATE, 31);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return sdf.format(c.getTime());
		}

		/**
		 * 获取当月的 天数
		 */
		public int getCurrentMonthDay() {
			Calendar a = Calendar.getInstance();
			a.set(Calendar.DATE, 1);
			a.roll(Calendar.DATE, -1);
			int maxDate = a.get(Calendar.DATE);
			return maxDate;

		}

		/**
		 * 获取过去第几天的日期
		 *
		 * @param past
		 * @return
		 */
		public String getBeforeDate(int past) {
			Calendar calendar = Calendar.getInstance();
			calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
			Date today = calendar.getTime();
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			String result = format.format(today);
			return result;
		}

		/**
		 * 获取本周的所有日期
		 *
		 * @return
		 */
		public List<String> getWeakDayList() {
			List<String> lDate = new ArrayList();
			Calendar cal = Calendar.getInstance();
			// 判断要计算的日期是否是周日，如果是则减一天计算周六的，否则会出问题，计算到下一周去了
			int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
			if (1 == dayWeek) {
				cal.add(Calendar.DAY_OF_MONTH, -1);
			}
			for (int i = 0; i < 7; i++) {
				cal.add(Calendar.DATE, -1 * cal.get(Calendar.DAY_OF_WEEK) + 2 + i);
				lDate.add(sdf.format(cal.getTime()));
			}
			return lDate;
		}

		/**
		 * 获取本周的所有日期(格式为日期 )
		 *
		 * @return
		 */
		public List<String> getWeakDayDayList() {
			// 日期格式化
			SimpleDateFormat sdfDay = new SimpleDateFormat("dd");
			List<String> lDate = new ArrayList();
			Calendar cal = Calendar.getInstance();
			// 判断要计算的日期是否是周日，如果是则减一天计算周六的，否则会出问题，计算到下一周去了
			int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
			if (1 == dayWeek) {
				cal.add(Calendar.DAY_OF_MONTH, -1);
			}
			for (int i = 0; i < 7; i++) {
				cal.add(Calendar.DATE, -1 * cal.get(Calendar.DAY_OF_WEEK) + 2 + i);
				lDate.add(sdfDay.format(cal.getTime()));
			}
			return lDate;
		}

		/**
		 * 获取上周的所有日期
		 *
		 * @return
		 */
		public List<String> getLastWeakDayList() {
			List<String> lDate = new ArrayList();
			Calendar cal = Calendar.getInstance();
			// 判断要计算的日期是否是周日，如果是则减一天计算周六的，否则会出问题，计算到下一周去了
			int dayWeek = cal.get(Calendar.DAY_OF_WEEK);// 获得当前日期是一个星期的第几天
			if (1 == dayWeek) {
				cal.add(Calendar.DAY_OF_MONTH, -1);
			}
			// 周减一
			cal.add(Calendar.WEEK_OF_MONTH, -1);
			for (int i = 0; i < 7; i++) {
				cal.add(Calendar.DATE, -1 * cal.get(Calendar.DAY_OF_WEEK) + 2 + i);
				lDate.add(sdf.format(cal.getTime()));
			}
			return lDate;
		}

		/**
		 * 获取本月的所有日期
		 *
		 * @return
		 */
		public List<String> getMonthDayList() {
			Calendar calendar = Calendar.getInstance();
			int index = calendar.get(Calendar.DAY_OF_MONTH);
			calendar.add(Calendar.DATE, (1 - index));
			Date weekBegin = calendar.getTime();

			//
			calendar = Calendar.getInstance();
			calendar.add(Calendar.MONTH, 1);
			index = calendar.get(Calendar.DAY_OF_MONTH);
			calendar.add(Calendar.DATE, (-index));
			Date weekEnd = calendar.getTime();

			List<String> lDate = new ArrayList();
			lDate.add(sdf.format(weekBegin));
			Calendar calBegin = Calendar.getInstance();
			// 使用给定的 Date 设置此 Calendar 的时间
			calBegin.setTime(weekBegin);
			Calendar calEnd = Calendar.getInstance();
			// 使用给定的 Date 设置此 Calendar 的时间
			calEnd.setTime(weekEnd);
			// 测试此日期是否在指定日期之后
			while (weekEnd.after(calBegin.getTime())) {
				// 根据日历的规则，为给定的日历字段添加或减去指定的时间量
				calBegin.add(Calendar.DAY_OF_MONTH, 1);
				lDate.add(sdf.format(calBegin.getTime()));
			}
			return lDate;
		}

		/**
		 * 获取本月的所有日期(格式为日期 )
		 *
		 * @return
		 */
		public List<String> getMonthDayDayList() {
			// 日期格式化
			SimpleDateFormat sdfDay = new SimpleDateFormat("dd");

			Calendar calendar = Calendar.getInstance();
			int index = calendar.get(Calendar.DAY_OF_MONTH);
			calendar.add(Calendar.DATE, (1 - index));
			Date weekBegin = calendar.getTime();

			//
			calendar = Calendar.getInstance();
			calendar.add(Calendar.MONTH, 1);
			index = calendar.get(Calendar.DAY_OF_MONTH);
			calendar.add(Calendar.DATE, (-index));
			Date weekEnd = calendar.getTime();

			List<String> lDate = new ArrayList();
			lDate.add(sdfDay.format(weekBegin));
			Calendar calBegin = Calendar.getInstance();
			// 使用给定的 Date 设置此 Calendar 的时间
			calBegin.setTime(weekBegin);
			Calendar calEnd = Calendar.getInstance();
			// 使用给定的 Date 设置此 Calendar 的时间
			calEnd.setTime(weekEnd);
			// 测试此日期是否在指定日期之后
			while (weekEnd.after(calBegin.getTime())) {
				// 根据日历的规则，为给定的日历字段添加或减去指定的时间量
				calBegin.add(Calendar.DAY_OF_MONTH, 1);
				lDate.add(sdfDay.format(calBegin.getTime()));
			}
			return lDate;
		}

		/**
		 * 获取上月的所有日期
		 *
		 * @return
		 */
		public List<String> getLastMonthDayList() {
			Calendar calendar = Calendar.getInstance();
			calendar.add(Calendar.MONTH, -1);
			int index = calendar.get(Calendar.DAY_OF_MONTH);
			calendar.add(Calendar.DATE, (1 - index));
			Date weekBegin = calendar.getTime();

			//
			calendar = Calendar.getInstance();
			calendar.add(Calendar.MONTH, -1);
			calendar.add(Calendar.MONTH, 1);
			index = calendar.get(Calendar.DAY_OF_MONTH);
			calendar.add(Calendar.DATE, (-index));
			Date weekEnd = calendar.getTime();

			List<String> lDate = new ArrayList();
			lDate.add(sdf.format(weekBegin));
			Calendar calBegin = Calendar.getInstance();
			// 使用给定的 Date 设置此 Calendar 的时间
			calBegin.setTime(weekBegin);
			Calendar calEnd = Calendar.getInstance();
			// 使用给定的 Date 设置此 Calendar 的时间
			calEnd.setTime(weekEnd);
			// 测试此日期是否在指定日期之后
			while (weekEnd.after(calBegin.getTime())) {
				// 根据日历的规则，为给定的日历字段添加或减去指定的时间量
				calBegin.add(Calendar.DAY_OF_MONTH, 1);
				lDate.add(sdf.format(calBegin.getTime()));
			}
			return lDate;
		}

		String[] hoursList = { "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00", "24:00" };

		String[] quarterList = { "1", "2", "3", "4" };

		String[] monthList = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" };

	}

	/**
	 * 获取日的数据
	 *
	 * @param hoursList
	 * @param mapList
	 * @param dataList
	 */
	private void getDayData(String[] hoursList, List<Map<String, Object>> mapList, List<String> dataList) {
		for (String hours : hoursList) {
			boolean flag = true;
			for (Map<String, Object> map : mapList) {
				if (hours.equals(map.get("queryDate"))) {
					Object obj = map.get("amount");
					String value = "";
					if (obj instanceof Integer) {
						value = (Integer) obj + "";
					} else if (obj instanceof Long) {
						value = (Long) obj + "";
					} else if (obj instanceof BigDecimal) {
						value = ((BigDecimal) obj).toEngineeringString();
					} else {
						value = (String) obj;
					}
					dataList.add(value);
					flag = false;
					break;
				}
			}
			if (flag) {
				dataList.add("0");
			}
		}
	}

	/**
	 * 获取日的数据
	 *
	 * @param list
	 * @param mapList
	 * @param dataList
	 */
	private void getWeakMonthData(List<String> list, List<Map<String, Object>> mapList, List<String> dataList) {
		for (String month : list) {
			if (month.length() == 6) {
				month = month.substring(0, 5) + "0" + month.substring(5, 6);
			}
			boolean flag = true;
			for (Map<String, Object> map : mapList) {
				if (month.equals(map.get("date"))) {
					Object obj = map.get("amount");
					String value = "";
					if (obj instanceof Integer) {
						value = (Integer) obj + "";
					} else if (obj instanceof Long) {
						value = (Long) obj + "";
					} else if (obj instanceof BigDecimal) {
						value = ((BigDecimal) obj).toEngineeringString();
					} else {
						value = (String) obj;
					}
					dataList.add(value);
					flag = false;
					break;
				}
			}
			if (flag) {
				dataList.add("0");
			}
		}
	}

	/*
	 * 距离当前时间运算
	 */
	public void forTimeWay(List<Player> list) throws Exception{
		//玩家ID
		List<String> playerIdsList = new ArrayList<>();
		if (list != null && list.size() > 0) {
			for (Player player : list) {
				if (player != null) {
					player.setUserId(player.getPlayerId());
					if (player.getNickName() != null) {
						player.setName(player.getNickName());
					}
					if(player.getLoginTime() != null) {
						player.setLastLoginTimeFormat(TimeFormatUtil.timeUtile(player.getLoginTime()));// 未登录的天数
					}
					playerIdsList.add(player.getPlayerId());
				}
			}
		}
		getPlayerIsOnline(list,playerIdsList);
	}

	/**
	 * 获取玩家是否在线
	 * @param list
	 * @param playerIdsList
	 * @throws Exception
	 */
	private void getPlayerIsOnline(List<Player> list,List<String> playerIdsList) throws Exception
	{
		TreeMap<String, Object> paramMap = new TreeMap<>();
		paramMap.put("playerIds", String.join(",",playerIdsList));
		Map resultMap = QueryAppUtil.query("playerOnlineUrl", 1, paramMap);
		Integer code = Integer.parseInt(resultMap.get("code").toString());
		JSONArray data = new JSONArray();
		if (code == 1) {
			data = JSONArray.parseArray(resultMap.get("data").toString());
		} else {
			logger.error(resultMap.get("msg").toString());
		}
		if(data!=null&&data.size()>0)
		{
			for (Object playerId : data) {
				setPlayerIsOnline(list,playerId.toString());
			}
		}
	}

	/**
	 * 修改玩家是否在线标志
	 * @param list
	 * @param playerId
	 */
	private void setPlayerIsOnline(List<Player> list,String playerId)
	{
		if (list != null && list.size() > 0) {
			for(int i=0;i<list.size();i++)
			{
				Player player=list.get(i);
				if(player.getPlayerId().equals(playerId))
				{
					player.setIsOnline(1);
					break;
				}
			}
		}
	}

	/**
	 * 查询所有的子集id
	 *
	 * @param parentCode
	 * @param list
	 * @throws Exception
	 */
	private void selectDeptSon(String parentCode, List<String> list) throws Exception {
		List<Dept> deptList = this.deptMapper.selectByParentCode(parentCode);

		if (deptList != null) {
			for (Dept dept1 : deptList) {
				list.add(dept1.getId());
				selectDeptSon(dept1.getCode(), list);
			}
		}
	}

	/**
	 * 查询公会id
	 *
	 * @param code
	 * @throws Exception
	 */
	private String selectLabourUnionId(String code) throws Exception {
		Dept dept = this.deptMapper.selectByCode(code);
		if (dept != null) {
			if (dept.getType() != null && dept.getType() == 1) {
				return dept.getName();
			} else {
				return selectLabourUnionId(dept.getParentCode());
			}
		} else {
			return null;
		}
	}

	/**
	 * 递归查找部门的顶级
	 *
	 * @return
	 */
	private Dept selectTopDept(String code) throws Exception {
		Dept dept = this.deptMapper.selectByCode(code);
		if (dept.getType() == 2) {
			return dept;
		} else {
			return selectTopDept(dept.getParentCode());
		}
	}

}
